ag-grid:总计位于枢轴底部,具有分组的列

时间:2020-04-13 21:18:51

标签: java angular typescript ag-grid ag-grid-angular

我对与UI相关的角度和脚本非常陌生。 我有一个ag-grid-angular 12.0.0版本(旧的,不是最新的),并试图实现如下所示的功能。

enter image description here

基本上,我的2列(或更多列)数据集以数据透视模式(即日期和图书)分组。剩下的是求和的值列。

到目前为止(在摘要下方),我可以做到到这里:

enter image description here

-我的类型脚本- 粘贴主要流程或功能。

ngOnInit() {
    this.pivotMode = true;
    .
    .
    this.initializeColumns();
}

initializeColumns(): void {
    this.gridOptions.columnDefs = [
        { headerName: "Date", field: "date",  width: 120px, enableRowGroup: true, enablePivot: true, rowGroupIndex: 1},
        { headerName: "Book", field: "book", width: 120px, enableRowGroup: true, enablePivot: true, rowGroupIndex: 2 },
        { headerName: 'Field 1', field: 'field1', width: 120px, enableValue: true, aggFunc: 'sum', cellClass: 'text-right', filter: 'number' },
        .
        .
        .
}

getData(selection: any): void {
    this.noResults = false;
    this.myData = null;
    .
    .
    // httpservice call to get myData
    this.gridOptions.api.setRowData(this.myData);
    this.createTotalRow(this.myData);
}

createTotalRow(rows: object[]): void {
    // This is working fine and giving the total for each column properly.
    this.myDataTotals = this.methodToCalculate(rows);
    let totals = [];
    // Here is where I am stuck
    totals.push(
        date: 'Grand Total',
        book: 'Grand Total',
        field1: this.myDataTotals.field1 // Basically this will put the total calculated under this field.
        .
        .

    );
    this.gridOptions.api.setPinnedBottomRowData(totals);
}

因此,使用上面的方法,我获得了正确的数据(第二张快照),但无法在底部第一栏中打印“总计”字样。 如果我取消数据透视,则会看到“总计”列在日期和帐簿下。但是,我也需要在枢轴级别使用它。

我无法在mu“总计”数组中为其分配值。

我试图检查colId是ag-Grid-AutoColumn(可以是内部自动分配的值)。我不愿意在“总计”数组中给出相同的值,但是它不起作用。

请注意,我无法升级我的ag-grid版本(这不是个人版本,但可以使用)。

所以基本上希望知道如何使用第一列(分组列)? 我可以基于索引而不是键/值定义数组(总计)吗? (我真的是打字稿或不熟悉UI技术的初学者,所以没有太多想法)是否适合我的情况?

0 个答案:

没有答案