需要将使用columnGroupDefs进行列分组的代码中,将sort属性设置为null,然后在使用pivotMode和pivotColumnGroupDefs时,使用自定义的comparator函数。
以下是示例代码:
// 列分组定义 let columnGroupDefs = [ // 普通列 { headerName: "Athlete Details", children: [ {headerName: "Athlete", field: "athlete", minWidth: 200}, {headerName: "Age", field: "age", minWidth: 100, comparator: ageComparator}, {headerName: "Country", field: "country", minWidth: 150}, ] }, // 分组列 { headerName: "Medal Counts", groupId: "medalGroup", children: [ {headerName: "Gold", field: "gold", minWidth: 100, sort: null}, {headerName: "Silver", field: "silver", minWidth: 100, sort: null}, {headerName: "Bronze", field: "bronze", minWidth: 100, sort: null}, ] } ];
// 自定义排序比较器 function ageComparator(valueA, valueB, nodeA, nodeB, isInverted) { if (valueA == null && valueB == null) { return 0; } if (valueA == null) { return -1; } if (valueB == null) { return 1; }
return valueA - valueB;
}
// 使用pivotMode和pivotColumnGroupDefs gridOptions.pivotMode = true; gridOptions.pivotColumnGroupDefs = [ { headerName: "Country", field: "country", cellRenderer: "agGroupCellRenderer", comparator: countryComparator, minWidth: 150 } ];
// 自定义分组比较器 function countryComparator(valueA, valueB, nodeA, nodeB, isInverted) { if (valueA == null && valueB == null) { return 0; } if (valueA == null) { return -1; } if (valueB == null) { return 1; }
return valueA.localeCompare(valueB);
}
上一篇:Ag-grid列排序比较器在列分组的枢轴模式下无效。
下一篇:AG-Grid列重叠