Several arrays within the filteredData (MatTableDataSource) are being utilized

Hey there, I could really use some assistance. I have this data stored in a filteredData variable within a MatTableDataSource.

filteredData

My goal is to display this data in two separate tables, but I'm encountering issues where nothing is being shown.

Tables

In my component.ts file, I have the following:

    ngOnInit(): void {
        this.Groups();

    }

    Groups(){
        this.apiSvc.Cards().subscribe((rsp: any) => { 
            this.groups = rsp;

        });

        this.apiSvc.Cards().pipe(
            switchMap((rsp:any[])=>{

              return forkJoin(
                rsp.map(x=>this.apiSvc.Groups(x.id))
              )
            })
         ).subscribe((res:any[])=>{

            this.dataSource = new MatTableDataSource(res);
            this.dataSource.paginator = this.paginator;
            console.log(this.dataSource);
         })


Furthermore, here's what I've included in my component.html:

<table mat-table [dataSource]="dataSource" class="table employee-list no-wrap">
            
            <ng-container matColumnDef="#">
              <th mat-header-cell *matHeaderCellDef> ID </th>
              <td mat-cell *matCellDef="let element"> {{element.usersid}} </td>
            </ng-container>
</table>

My aim is to arrange the IDs based on the filteredData image order, potentially using ngFor for future data expansion, but I'm unsure how to accomplish this task.

Result

If anyone can provide guidance or assistance, I would be truly grateful. Thank you.

Answer №1

Every event is instantiating dataSource like this: this.dataSource = new MatTableDataSource(res);

Consider moving this to a constructor or NgOnInit method and updating your data on subscribe instead: .subscribe(list => this.datasource.data = list);

    Groups(){
    /* instantiate once */
    this.dataSource = new MatTableDataSource();

    this.apiSvc.Cards().subscribe((resp: any) => { 
        this.groups = resp;

    });

    this.apiSvc.Cards().pipe(
        switchMap((resp:any[])=>{
          return forkJoin(
            resp.map(x=>this.apiSvc.Groups(x.id))
          )
        })
     ).subscribe((result:any[])=>{
         /* fill your table here */
        this.dataSource.data = result;
        
        this.dataSource.paginator = this.paginator;
        console.log(this.dataSource);
     });

}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Launching an Angular application in a universal environment on Azure's service

My angular app is configured with Angular Universal. After the build pipeline, I have a server folder that I understand is necessary. However, when I use my app without server-side rendering (SSR), I point the path in Azure App Settings to my browser folde ...

There was an issue when attempting to create a unique component with the TAB feature in Angular Material

Looking to implement a custom TAB component using Angular Material 9. Here is the code snippet for creating a TAB with Angular Material: <mat-tab-group> <mat-tab label="First"> Content 1 </mat-tab> <mat-tab label=" ...

Can a Typescript class type be defined without explicitly creating a JavaScript class?

I am exploring the idea of creating a specific class type for classes that possess certain properties. For example: class Cat { name = 'cat'; } class Dog { name = 'dog'; } type Animal = ???; function foo(AnimalClass: Animal) { ...

Managing Access Control Origin Headers in an Angular 4 Application

I currently have a Play framework based REST API running locally on port 9000 of my machine. Additionally, I have an Angular 4 application running on port 4200 on the same localhost. My goal is to have this Angular app display the JSON data received from ...

I'm curious about how to link a JSON field using dot notation in Angular 12 HTML

Does anyone know how to bind a JSON field using dot paths in Angular 12 HTML? For example: //Angular data: any = { name: 'x1', address: { city: 'xyz' } }; field: any = 'address.city'; //Html <input [(ngModel)]="data[ ...

Slim API receives a request from Ionic 5

Seeking assistance with making a GET request from my Ionic application to an API constructed using the Slim Framework. Below is the code snippet of the API: <?php header('Access-Control-Allow-Origin: *'); header('Content-Type: applicati ...

Combine arrays of objects by comparing two attributes in Typescript

Suppose I have an array in TypeScript that looks like this: const array = [ { id_m: "123", period: "Q1/22", amount: 1000 }, { id_m: "123", period: "Q1/22", amount: 500 }, { id_m: "123&q ...

The yarn/npm package manager seems to be utilizing outdated code in an inexplicable way when paired with mocha and typescript

I recently encountered a strange issue that has left me scratching my head. When I manually run my test command, I receive two test results. However, when I execute the same command in a yarn/npm script, only one result is displayed. Has anyone else experi ...

Tips on how to combine or flatten arrays using rxJS

I am looking to consolidate a structured array into one uniform array. The original array structure is as follows: [ { "countryCode": "CA", "countryName": "Canada", "states": [ { "stateCode": "CAAB", "stateName": "Alber ...

Having trouble utilizing the ng-Command in Angular?

Currently, I am attempting to set up Angular in a vagrant-box environment. npm install -g @angular/cli Unfortunately, I encounter an error while trying to use the client: The program 'ng' is currently not installed. You can install it by typin ...

Navigating with Angular 2 using separate modules but sharing the same routing

What if I have two main routes, both loading the same child module? Is it possible to have two routes with the same name on the child module that load two different components based on the main route? Main Routes: export const ROUTES: Routes = [{ pat ...

Guide to simulating a function using .then within a hook

I am using a function that is called from a hook within my component. Here is my component: ... const handleCompleteContent = (contentId: string) => { postCompleteContent(contentId, playerId).then(data => { if (data === 201) { ... The caller ...

What type of HTML tag does the MUI Autocomplete represent?

Having trouble calling a function to handle the onchange event on an autocomplete MUI element. I've tried using `e: React.ChangeEvent`, but I can't seem to locate the element for the autocomplete component as it throws this error: The type &apos ...

Production environment experiencing issues with FCM service worker functionality

Upon testing the production build on localhost, Firebase Cloud Messaging (fcm) functions correctly. However, when attempting to run it on my AWS EC2 instance, I encountered the following error: An Unhandled Promise rejection occurred: Messaging: We are un ...

Tips for preventing words from being split between lines in an error message

I am encountering a problem in Angular 2 where error messages are being split onto two lines when there isn't enough space for the entire word. Check out this screenshot for reference Is it possible to prevent words from being divided across lines? ...

What is the best way to set up TypeScript interfaces using predefined string literals to limit the possible data types for shared attributes?

In this scenario, we have two interfaces named A and B with validation and variant properties. The goal is to create an Example object by using only the variant and validation values provided (since field is already defined). However, I encountered an erro ...

Having difficulty grasping the significance of the data received from the API response

Currently, as I am working on my personal Portfolio for a Web Developer course, I have encountered an issue with correctly implementing my API to retrieve information from the database. Previously, I faced no problem when using a .json file, but now, I am ...

What is the easiest way to retrieve a basic date with the month represented by a numerical

Struggling to retrieve the date in the format "Oct 29". I attempted using split but it varies every day. This is what I've come up with so far. let currentDate = new Date().toLocaleDateString('en-US', { month: 'short', day: 'n ...

Find the identifier that does not currently exist in the collection of objects

There is a situation where I have an array and an object that consists of arrays of ids, which are essentially permission objects. My goal now is to extract the ids that do not exist in the given object. Can someone assist me with devising the necessary l ...

Utilizing Angular 2 and appengine with Python to successfully pass a basic GET request

I am currently attempting to run Angular 2 on the front end and App Engine Python on the back end. To achieve this, I have launched the App Engine Python backend server using dev_appserver.py --port 3030 app.yaml, and the Angular 2 frontend server using "n ...