我有一个 dojox.grid.DataGrid,我想在其中以编程方式选择一行。我正在使用 setSelected() 这样做并且它第一次起作用。但是,为不同的行再次调用它会使前一行突出显示。此外,如果我尝试重新选择以前选择的行,则不会触发 onSelected 事件。但是,如果我真的在网格中单击,它会清除所有内容:在未突出显示和未选择之前在网格中突出显示的行。
代码如下所示:
if (grid.rowCount > 0 && idx < grid.rowCount)
{
grid.selection.setSelected(idx, true);
grid.render();
}
就好像我启用了多选,但我已将网格声明为 selectionMode="single"。
<table dojoType="dojox.grid.DataGrid"
id="hotTablesForAppDg"
autoWidth="true" autoHeight="true" selectionMode="single"
onSelected="autonomics.Clusters.loadTableDetails(this)">
我还需要调用其他什么来清除之前的选择吗?
最佳答案
问题解决了。您需要在当前选择的索引上调用 setSelected(..., false) :
if (grid.rowCount > 0 && idx < grid.rowCount)
{
if (grid.selection.selectedIndex >= 0)
{
// If there is a currently selected row, deselect it now
grid.selection.setSelected(grid.selection.selectedIndex, false);
}
grid.selection.setSelected(idx, true);
grid.render();
}
关于dojo - dojo DataGrid 中的 setSelected() 即使对于具有 selectionMode ="single"的网格也会使先前的选择保持事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11266389/