table 更改时,SlickGrid DataView syncGridSelection 不会删除旧选择

SlickGrid DataView syncGridSelection does not remove the old selection when the table changes

我有一个 SlickGrid 运行 和一个 dataView,我正在使用带有选项 multiSelect=falserowSelectionModel。当我 select 网格中的某些东西然后通过单击按钮展开我的网格以显示一些隐藏的行时,selection 正在正确移动,但旧的 selection 仍然保留在旧行。

这是我目前拥有的:

var dataView = new Slick.Data.DataView({inlineFilters: false});
var grid = new Slick.Grid(gridDiv, dataView, columns, options);
grid.setSelectionModel(new Slick.RowSelectionModel({selectActiveRow: true}));
grid.setSelectedRows([]); //make sure the selection is empty
dataView.onRowsChanged.subscribe(function (e, args) {
    grid.invalidate();
});
dataView.beginUpdate();
dataView.setItems(data);
dataView.setFilter(displayFilter);
dataView.endUpdate();
dataView.syncGridSelection(grid);
grid.render();

以下是该行为的一些屏幕截图:

展开前:

扩展后的预期行为:

扩展后的实际行为:

我很确定我很接近,但我不太清楚我做错了什么。

提前感谢您抽出宝贵时间帮助我:)

编辑:我可能发现了什么。我正在使用 syncGridSelection 设置一些事件,但稍后会覆盖它们。我覆盖的事件是 dataView.onRowCountChanged() dataView.onRowsChanged() grid.onSelectedRowsChanged

这可能是这里的问题吗?我需要这些事件才能使 collapse/expand 功能发挥作用。 grid.onSelectedRowsChanged 用于将 selected 项传递给图表,因此也是必需的。

编辑 2: 我能够通过示例 5 重现该问题,可以找到修改后的代码 in this paste 重现步骤: 1. Select 项目 10 2. 折叠项目 7

查看代码后,我认为这实际上是 工作。只是你的CSS改动遮蔽了一点。

已选择行和有效行。这些是不同的东西。您已将两者的 CSS(在页面本身的 CSS 区域中)设置为看起来相同。所以看起来选择仍然存在,但实际上它已被删除,但该行现在处于活动状态。

把那两条CSS规则删掉看看

如需加分,请使用:

dataView.syncGridSelection(grid, true);

and the grid will preserve the selections as the selection moves in and out of sight on collapse/expand.