This is a migrated thread and some comments may be shown as answers.

Using aggregates on Dynamically created columns

1 Answer 586 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tina
Top achievements
Rank 1
Tina asked on 18 Sep 2019, 02:59 PM

Is there a way to select generated aggregates on dynamic columns.  I have verified that my code creating the totals is working but I am unable to utilize them in the HTML.  

Component code:

// Creating the aggregates

    this.operationalReportDataService.getVolumeTrend(this.choice)
    .pipe(
      finalize(() => this.grid.loading = false)
    )
    .subscribe((data: VolumeTrend) => {
      this.gridView = data.gridData;
      this.colSettings = data.dateColumns;
      data.dateColumns.forEach(x => this.aggregates.push({ field: x.field, aggregate: 'sum' }));
    });

// Generating the values

  private setAverageAndTotals(data: any[]) {
    // tslint:disable-next-line:max-line-length
    this.totalsAndAverages = aggregateBy(data, this.aggregates);
  }

 

HTML:

<kendo-grid-column
    *ngFor="let col of this.colSettings"
      field="{{col.field}}"
      title="{{col.title}}"
      format="{{col.format}}" width="40" [footerClass]="{'grid-footer': true}">
      <ng-template
        kendoGridFooterTemplate *ngIf="this.totalsAndAverages && this.lastPage"
        let-column="column">Total {{column.title}}: {{totalsAndAverages["{column.title}"].sum}}
      </ng-template>
  </kendo-grid-column>

1 Answer, 1 is accepted

Sort by
0
Tina
Top achievements
Rank 1
answered on 18 Sep 2019, 04:37 PM

Found the trick: 

 

ML:
<kendo-grid-column
    *ngFor="let col of this.colSettings"
      field="{{col.field}}"
      title="{{col.title}}"
      format="{{col.format}}" width="40" [footerClass]="{'grid-footer': true}">
      <ng-template
        kendoGridFooterTemplate *ngIf="this.totalsAndAverages && this.lastPage"
        let-dataItem>Total {{dataItem.field}}: {{totalsAndAverages[dataItem.field].sum}}
      </ng-template>
  </kendo-grid-column>

Tags
Grid
Asked by
Tina
Top achievements
Rank 1
Answers by
Tina
Top achievements
Rank 1
Share this question
or