[英]Adding a custom “ALL” (Total) row to the top of an ag-grid that is selectable like any other row
我有一个包含 2 列的 ag-grid 表 - 一个文本和一个数字。
我需要在我的 ag-grid 表的顶部添加一个自定义行,其中包含数字列的总值和文本列中的“ALL”一词。
这需要在顶部。 即使表格已排序,也不应更改其位置。
此外,该行应该是可选择的。
在这方面的任何帮助将不胜感激!
听起来你在描述行固定,这已经是 AG Grid 中的一个功能。 但是,由于您还声明行选择是一项要求,因此 Row Pinning 无法实现,因为它不受支持。
相反,我建议在rowData
为自定义行添加一个额外的行对象,并在必要时自己处理数字列和自定义行位置的更新:
如果要处理数字列的总值,则可以使用以下逻辑:
function updateTotalRowNode() {
let totalRowNode;
let sum = 0;
gridOptions.api.forEachNode((node) => {
if (node.data.totalRow) {
totalRowNode = node;
} else {
sum += node.data.gold;
}
});
totalRowNode.setDataValue('gold', sum);
}
如果要始终将自定义行保留在顶行,则可以 实现postSort
回调:
postSort: (rowNodes) => {
// here we put All row on top while preserving the sort order
let nextInsertPos = 0;
for (let i = 0; i < rowNodes.length; i++) {
const athlete = rowNodes[i].data.athlete;
if (athlete === 'All') {
rowNodes.splice(nextInsertPos, 0, rowNodes.splice(i, 1)[0]);
nextInsertPos++;
}
}
},
有关实现,请参阅以下 plunker 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.