您在问题中引用的 SO 答案是错误的,displayTotalsRow 不是 DataView 上存在的标志,而是组信息 (grouping) 中存在的标志,如 line 所示的 DataView (slick.dataview.js),这已经在 Angular-Slickgrid grouping: { 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 界面here
数据视图
为了进一步参考,并证明该标志不是有效的 DataView 选项,如果您只查看 slick.dataview.js 文件的顶部,您会立即在类定义中看到只有 2 个可用标记为可接受的 DataView 选项(defaults 变量如下所示)。所以有时候看看内部确实会有所帮助。
function DataView(options) {
var self = this;
var defaults = {
groupItemMetadataProvider: null,
inlineFilters: false
};
// ...