question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Table] Add a footer row (e.g. totals)

See original GitHub issue

Bug, feature request, or proposal:

feature reques

What is the expected behavior?

Add total row:

  <md-table [dataSource]="dataSource">

    <!-- Name Column -->
    <ng-container mdColumnDef="name">
      <md-header-cell *mdHeaderCellDef> Name </md-header-cell>
      <md-cell *mdCellDef="let row"> {{row.name}} </md-cell>
      <md-total-cell *mdTotalCellDef> Total </md-total-cell>
    </ng-container>

    <!-- Count Column -->
    <ng-container mdColumnDef="count">
      <md-header-cell *mdHeaderCellDef> Count </md-header-cell>
      <md-cell *mdCellDef="let row"> {{row.count}} </md-cell>
      <md-total-cell *mdTotalCellDef> {{dataSource.sumBy('count')}} </md-total-cell>
    </ng-container>

    <md-header-row *mdHeaderRowDef="displayedColumns"></md-header-row>
    <md-row *mdRowDef="let row; columns: displayedColumns;"></md-row>
    <md-total-row *mdTotalRowDef="displayedColumns"></md-total-row>
  </md-table>

Result:

Name       Count 
row 1       1        
row 2       2
Total       3

Or something like md-pagination.

  <md-table [dataSource]="dataSource">

    <!-- Name Column -->
    <ng-container mdColumnDef="name">
      <md-header-cell *mdHeaderCellDef> Name </md-header-cell>
      <md-cell *mdCellDef="let row"> {{row.name}} </md-cell>
    </ng-container>

    <!-- Count Column -->
    <ng-container mdColumnDef="count">
      <md-header-cell *mdHeaderCellDef> Count </md-header-cell>
      <md-cell *mdCellDef="let row"> {{row.count}} </md-cell>
    </ng-container>

    <md-header-row *mdHeaderRowDef="displayedColumns"></md-header-row>
    <md-row *mdRowDef="let row; columns: displayedColumns;"></md-row>
  </md-table>

  <md-table-total [dataSource]="dataSource">

    <!-- Name Column -->
    <ng-container mdColumnDef="name">
      <md-total-cell *mdTotalCellDef> Total </md-total-cell>
    </ng-container>

    <!-- Count Column -->
    <ng-container mdColumnDef="count">
      <md-total-cell *mdTotalCellDef> {{dataSource.sumBy('count')}} </md-total-cell>
    </ng-container>
  </md-table-total>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:27 (11 by maintainers)

github_iconTop GitHub Comments

8reactions
pantoniscommented, Nov 5, 2017

@andrewseguin Why is this minor? Is there any workaround that works without any issues? From what you said your workaround above does not work well. 😃

7reactions
timwright35commented, Dec 20, 2017

I was just wondering if the discussion was still happening on this or if this is dead in the water. Could really use this in my current project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add a Total Row to the footer of html table
Solved: I am running a SQL query that outputs the below There are more than 3 EventTypes (maybe 12 in total), but I've...
Read more >
Sum a column of numbers in a repeating table
In the footer row, click the cell in the column where you want to add the Total box. · On the Insert menu,...
Read more >
How to enable or show total row in footer of ag-grid table
1st step - Generate Pinned Total Row: Below function will generate an empty target object with all your columns available in the grid....
Read more >
Adding a total in the footer. — DataTables forums
Hello Forums, I am using DataTables for the first time. I came to this problem where I need the sum of rows in...
Read more >
Footer callback - DataTables example
The example below shows a footer callback being used to total the data for a column (both the visible and the hidden data)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found