在我的项目中,onSelectedRowsChanged事件可以在行更改时触发,但也可以在同一行中更改acitve单元格时触发,实际上我们不希望它发生。它在slickgrid exaple4-model.html页面中进行了测试,代码在这里:
grid.onSelectedRowsChanged.subscribe(function (e, args) {
window.console.log("fire selected events...");
});
有人能找到一个很好的解决方案来避免这种情况吗?感谢您的回复或建议。
答案 0 :(得分:3)
//This works for me:
grid.setSelectionModel(new Slick.RowSelectionModel());
//onCellChange event, track current row.
var rowIndex;
grid.onCellChange.subscribe(function (e, args) {
rowIndex = args.row;
});
//onSelectedRowsChanged event, if row number was changed call some function.
grid.onSelectedRowsChanged.subscribe(function (e, args) {
if (grid.getSelectedRows([0])[0] !== rowIndex) {
call function;
}
});
答案 1 :(得分:0)
这项工作对我来说
//Declare Global Variable
var lastSelectedId;
grid.onCellChange.subscribe(function (e, args) {
var selectedItem = grid.getDataItem(grid.getSelectedRows(0[0]);
if (selectedItem.id != lastSelectedId){
//Actions go here!
}
lastSelectedId = selectedItem.id
});