SetSelected () in the dojo DataGrid leaves the previous selection active even for the grid with the choiceMode = "single"

I have dojox.grid.DataGrid where I want to select a row programmatically. I am using setSelected () for this and it works for the first time. However, by calling it a second time for another line, you highlight the previous line. Also, if I try to reselect a row that was previously selected, the onSelected event does not fire. But if I actually clicked in the grid, it will clear things: the lines that were highlighted in the grid before getting immeasurable and unselected.

The code looks like this:

if (grid.rowCount > 0 && idx < grid.rowCount) { grid.selection.setSelected(idx, true); grid.render(); } 

As if I have multi-select enabled, but I declared the grid as selectionMode = "single".

 <table dojoType="dojox.grid.DataGrid" id="hotTablesForAppDg" autoWidth="true" autoHeight="true" selectionMode="single" onSelected="autonomics.Clusters.loadTableDetails(this)"> 

Is there anything else I need to clear my previous selection?

+4
source share
2 answers

The problem is resolved. You need to call setSelected (..., false) in the currently selected index:

 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(); } 
+8
source

I had the same problem from the grid in which the previous selection was active. The next line of code is grid.selection.clear (); before calling render (), solved the problem. Hope this helps.

+7
source

All Articles