4

I am having trouble displaying data in the material table when the data is coming as a nested array of objects.

I would like to display the table which is currently displayed in the stackblitz.

If I changed the existing data with my newData variable it will start breaking whole table.

Can anybody guide me How I can achieve split header function with group of nested data in the material table?

I would like to achieve something like this.

Here is my stackblitz. https://stackblitz.com/edit/angular-bklajw-5foa62

enter image description here

4
  • 1
    Are you using "code" field inside "summary" obect? Commented Dec 18, 2020 at 15:25
  • yes first column "No" is coming from the code field Commented Dec 18, 2020 at 15:27
  • 1
    As you have grouping data means nested array also. The best way to handling it using a nested table inside a parent table. Commented Dec 18, 2020 at 15:32
  • Thanks vimal.. How I can make sticky header to this table ? stackoverflow.com/questions/65430713/… Commented Dec 23, 2020 at 21:39

1 Answer 1

1

the data source need to be an array of data you want to display. So you have to change

dataSource1 = newData;

to

dataSource1 = newData.data.summary;

You will also need to change the columns in the template since the objects are different, for example:

<td mat-cell *matCellDef="let element" class="similar-cell-width">{{ element.data[0].amount }}</td>
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for answer Chris..what if the positions will change in the array? Is there anyway to check the condition before using element.data[0].amount?
you can use regular typescript code between the {{ }}, even call a method (like {{ processData(element) }}). So you can do whatever array manipulation you want here.
Sorry, if I am asking much. Is it possible for you to provide an example in the stackblitz?stackblitz.com/edit/angular-bklajw-5foa62
Thanks Chris.. it worked, I just have one question that how I can apply style to header now? I am not able to add sticky header here. stackoverflow.com/questions/65430713/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.