Added aggregator (Fixes #13)

This commit is contained in:
Zakary Timson 2018-09-17 11:11:14 -04:00
parent a1418306fa
commit b8960b0eb2
5 changed files with 24 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/ng-datatable",
"version": "1.8.7",
"version": "1.9.7",
"homepage": "https://github.com/ztimson/ng-datatable",
"license": "Apache-2.0",
"author": {

View File

@ -1,6 +1,7 @@
import {TemplateRef} from "@angular/core";
export interface Column {
aggregate?: (rows: any[]) => any;
cssClass?: string; // CSS to add to column
hide?: boolean; // Hide column
hideMobile?: boolean; // Hide column on mobile

View File

@ -48,6 +48,13 @@
</td>
</tr>
</ng-container>
<tr class="ngdt-total">
<td *ngIf="showCheckbox && selectionMode !== null" class="ngdt-checkbox"></td>
<td *ngIf="expandedTemplate" class="ngdt-expand"></td>
<ng-container *ngFor="let c of columns">
<td class="ngdt-cell">{{aggregate(c)}}</td>
</ng-container>
</tr>
</tbody>
</table>
<nav *ngIf="paginate" [class]="paginateCssClass + 'ngdt-paginator'" aria-label="Page navigation">

View File

@ -75,6 +75,11 @@ export class NgDatatableComponent implements OnInit {
this.filterChanged.emit(this.filters);
}
aggregate(col: Column) {
if(!col.aggregate) return '';
return col.aggregate(this.processedData.map(row => this._dotNotation(row, col.property)));
}
changePage(page: number) {
if(!this.paginate || page < 1 || page > this.pages.length) return;
this.page = page;

File diff suppressed because one or more lines are too long