我有一个dojox.grid.DataGrid,我想以编程方式选择一行.我正在使用setSelected()这样做,它第一次工作.但是,对于不同的行再次调用它会使前一行突出显示.此外,如果我尝试重新选择之前选择的行
代码如下:
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();
}
