如何限制 SlickGrid 在任何特定时间最多突出显示单行?
我只想允许在网格中突出显示一行。如果用户选择一行,然后选择一个新行,则只有新行才会突出显示(同时,多选行处于关闭状态)。
在尝试执行此操作时,我设置了此事件:
grid.onSelectedRowsChanged.subscribe(function() { grid.setSelectedRows([1,2,3]); });
虽然它看起来有效,但速度非常慢(仅执行 50 行需要 3 秒),并且在 chrome 13 中,它返回 2 个错误:
1) Uncaught RangeError: Maximum call stack尺寸超出 2
)巨大的错误跟踪:
error>
c.fn.c.pushStack:23
c.each.c.fn:99
getCellNode:2277
removeCellCssStyles:1506
setCellCssStyles:1518
handleSelectedRangesChanged:925
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRowsslick.grid.js:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:12
是否有更好的方法来实现所需的功能?
I want to allow only a single row to ever be highlighted in my grid. If a user selects a row, then selects a new row, only the new row will be highlighted (also, multiselect row is off).
In attempting to do this, I set this event:
grid.onSelectedRowsChanged.subscribe(function() { grid.setSelectedRows([1,2,3]); });
although it appears to work, it is very slow (3 seconds to execute for only 50 total rows) and in chrome 13, it returns 2 errors:
1) Uncaught RangeError: Maximum call stack size exceeded
and
2) a huge error trace:
error>
c.fn.c.pushStack:23
c.each.c.fn:99
getCellNode:2277
removeCellCssStyles:1506
setCellCssStyles:1518
handleSelectedRangesChanged:925
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRowsslick.grid.js:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:125
trigger:789
handleSelectedRangesChanged:927
notify:125
setSelectedRanges:72
setSelectedRows:2478
grid.onAddNewRow.subscribe.item:546
notify:12
is there an better way to achieve the desired functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最大调用堆栈是由循环函数调用引起的。
您首先触发
onSelectedRowsChanged
事件(可能通过 onClick),该事件将调用上面的函数。但随后您的函数会调用setSelectedRows
来设置选定的行,然后触发onSelectedRowsChanged
。这将继续发生,直到 JS 引擎达到最大调用堆栈,然后停止(毕竟,我们不想让浏览器崩溃)。我认为唯一的解决方案是编写自己的 RowSelectionModel 并在其中执行 grid.setSelectedRows() 。
The maximum call stack is caused by the circular function calls.
You first trigger the the
onSelectedRowsChanged
event (probably via onClick) which will call your function above. But then your function callssetSelectedRows
which will set the selected rows and then trigger theonSelectedRowsChanged
. This will continue happening until the JS engine reaches the maximum call stack and then stops (after all, we don't want to crash the browser).I think the only solution is to write your own RowSelectionModel and perform the grid.setSelectedRows() in there.