0

我正在使用带有总和聚合器的分组来使其工作,但我实际上并不关心总和或任何其他信息,我只是对分组感兴趣。它工作正常,但我每组的总行都是空的,这看起来不太好。有没有办法摆脱它?

这里似乎解决方案是将 displayTotalsRow: false 传递给 dataView 构造函数,这是 angular-slickgrid 的可能性吗?

谢谢

4

1 回答 1

1

您在问题中引用的 SO 答案是错误的,displayTotalsRow它不是 DataView 上存在的标志,而是 Group Info ( grouping) 中存在的标志,如DataView ( ) 的这一slick.dataview.js所示,这已经在Angular-Slickgridgrouping: { getter: 'title', displayTotalsRow: false, aggregators: [...], ... }

groupByDuration() {
    this.dataviewObj.setGrouping({
      getter: 'duration',
      formatter: (g) => `Duration: ${g.value} <span style="color:green">(${g.count} items)</span>`,
      aggregators: [
        new Aggregators.Avg('percentComplete'),
        new Aggregators.Sum('cost')
      ],
      comparer: (a, b) => Sorters.numeric(a.value, b.value, SortDirectionNumber.asc),
      aggregateCollapsed: false,
      lazyTotalsCalculation: true,
      displayTotalsRow: false, // <<-- HERE is the flag you want to use
    } as Grouping);

    // you need to manually add the sort icon(s) in UI
    this.angularGrid.filterService.setSortColumnIcons([{ columnId: 'duration', sortAsc: true }]);
    this.gridObj.invalidate(); // invalidate all rows and re-render
  }

或使用可拖动分组

initializeGrid {
  this.columnDefinitions = [
      {
        id: 'title', name: 'Title', field: 'title',
        width: 70, minWidth: 50,
        cssClass: 'cell-title',
        filterable: true,
        sortable: true,
        grouping: {
          getter: 'title',
          formatter: (g) => `Title: ${g.value}  <span style="color:green">(${g.count} items)</span>`,
          aggregators: [
            new Aggregators.Sum('cost')
          ],
          displayTotalsRow: false, // <<-- HERE is the flag you want to use
          aggregateCollapsed: false,
          collapsed: false
        }
      },
  ];
}

分组接口

可以在这里看到带有所有可能标志/选项的 Angular-Slickgrid TypeScript 界面

数据视图

为了进一步参考,并证明该标志不是有效的 DataView 选项,如果您只查看slick.dataview.js文件的顶部,您将立即在类定义中看到只有 2 个可用标志作为可接受的 DataView 选项(变量如下defaults所示)。因此,有时查看内部​​确实会有所帮助。

  function DataView(options) {
    var self = this;

    var defaults = {
      groupItemMetadataProvider: null,
      inlineFilters: false
    };
// ...
于 2020-08-03T14:58:14.413 回答