[英]AG-GRID : Infinite loop between onRowSelected and setSelected
I'm trying to select some rows depending on if i select or deselect a row, if i select a row, the rows with the index lower than the index of the selected row, will be slected too.我试图根据我选择还是取消选择一行来选择一些行,如果我选择一行,索引低于所选行索引的行也将被选择。 The problem that i have is that each time the setSelected(true) or setSelected(false) is executed, the onRowSelected event is triggered again, and it becomes an infinite loop.
我遇到的问题是,每次执行 setSelected(true) 或 setSelected(false) 时,都会再次触发 onRowSelected 事件,变成无限循环。
this.gridOptions.onRowSelected = function(event) {
var rowIndexSelected = event.rowIndex;
if (event.node.selected) {
vm.gridOptionsSuiviPrestataire.api.forEachNode(function(rowNode, index) {
if (index < rowIndexSelected) {
rowNode.setSelected(true);
}
});
} else {
vm.gridOptionsSuiviPrestataire.api.forEachNode(function(rowNode, index) {
if (index > rowIndexSelected) {
rowNode.setSelected(true);
}
});
}
};
Is there a way to do this without triggering the onRowSelected event listener or to use some flag to prevent executing the code inside of the method ?有没有办法在不触发 onRowSelected 事件侦听器或使用某些标志来阻止执行方法内部的代码的情况下执行此操作?
node.setSelected
has a third parameter called suppressFinishActions
but currently it only suppresses onSelectionChanged
event. node.setSelected
有第三个参数叫suppressFinishActions
但目前它只抑制onSelectionChanged
事件。 This is a limitation for which ag-Grid has two items in the backlog (AG-2859 and AG-2707).这是 ag-Grid 在 backlog 中有两个项目(AG-2859 和 AG-2707)的限制。 I'm not sure when they will provide the fix.
我不确定他们什么时候会提供修复程序。
For now you could try doing node.selected = true
but I've noticed that rows selected in this way don't have a highlight which is added via manual selection or setSelected
.现在你可以尝试做
node.selected = true
但我注意到以这种方式选择的行没有通过手动选择或setSelected
添加的突出显示。
Hope this will help you.希望这会帮助你。
let rowSelected = false;
this.gridOptions.onRowSelected = function (event) {
if (rowSelected) {
return;
}
var rowIndexSelected = event.rowIndex;
if (event.node.selected) {
vm.gridOptions.api.forEachNode(function (rowNode, index) {
if (index < rowIndexSelected) {
rowSelected = true;
rowNode.setSelected(true);
}
});
} else {
vm.gridOptions.api.forEachNode(function (rowNode, index) {
if (index > rowIndexSelected) {
rowSelected = true;
rowNode.setSelected(true);
}
});
}
rowSelected = false;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.