我在slickgrid中的行主要使用箭头键选择(突出显示),但允许鼠标选择。我在slickgrid外面有一个按钮,当按下这个按钮时,就会得到slickgrid中突出显示(选中)的行。在进行选择(突出显示)之后,slickgrid中不会发生任何事件(例如grid.onClick、grid.onKeyDown等),因此我不知道如何找到突出显示(选中)的行,特别是在单击按钮时。可以将事件以编程方式生成到slickgrid中以实现此目的吗?任何帮助都将不胜感激。
发布于 2021-12-03 11:37:14
我只能假设你没有使用slick.checkboxselectcolumn和slick.rowselectionmodel.js的专用插件,你可以看到这个Example,从中你可以访问onSelectedRowsChanged事件,如果你选择单击它,那么点击该行的任何地方都会触发事件(但是如果你使用多行选择,那么它只会从左边的列复选框触发)
import '../plugins/slick.checkboxselectcolumn.js';
import '../plugins/slick.rowselectionmodel.js';
grid = new Slick.Grid("#myGrid", data, columns, options);
grid.setSelectionModel(new Slick.RowSelectionModel({selectActiveRow: false}));
grid.registerPlugin(checkboxSelector2);
grid.onSelectedRowsChanged.subscribe(function (e, args) {
// debugging to see the active row in response to questions
// active row has no correlation to the selected rows
// it will remain null until a row is clicked and made active
// selecting and deselecting rows via checkboxes will not change the active row
var rtn = args.grid.getActiveCell();
var x = args.rows;
});从行索引中,有多种方法可以检索相关的item对象,在我的例子中,我使用SlickGrid DataView,并使用以下命令检索它
for (const row of args.rows) {
const itemObj = dataView.getItem(row);
// do something
}对于SlickGrid和DataView中的不同行为,有多种方法
// -- DataView --//
/** Get DataView item at specific index */
getItem(index: number) => any;
/** Get an item in the DataView by its Id */
getItemById(id: string | number) => any | null;
/** Get an item in the DataView by its row index */
getItemByIdx(idx: number) => any;
/** Get row index in the DataView by its Id */
getIdxById(id: string | number): number | undefined;// -- SlickGrid --//
/**
* Returns the databinding item at a given position.
* @param index Item row index.
*/
getDataItem(rowIndex: number): any;https://stackoverflow.com/questions/70208589
复制相似问题