1
votes

Here's my problem: in my application I have a Dojo EnhancedGrid, backed up by an ItemFileReadStore. The page flow looks like this:

  1. The user selects a value from a selection list.
  2. The item from the list is posted on a server and then the grid is updated with data from the server (don't ask why, this is how it's supposed to work)
  3. The new item is highlighted in the grid.

Now, the first two steps work like a charm; however, the third step gave me some headaches. After the data is successfully POSTed to the server (via dojo.xhrPost() ) the following code runs:

myGrid.store.close();
myGrid._refresh();
myGrid.store.fetch({
    onComplete : function(items) {
        for ( var i = 0; i < items.length; i++) {
             if (items[i].documentType[0].id == documentTypeId) {                                               
                 var newItemIndex = myGrid.getItemIndex(items[i]);
                 exportMappingGrid.selection.deselectAll();
                 exportMappingGrid.selection.addToSelection(newItemIndex);
             }
     }
      }
     });

Now, the selection of the grid is updated (i.e. the selection object has a selectedIndex > 0), but visually there's no response, unless I hover the mouse over the "selected" row. If I remove the .deselectAll() line (which I suspected as the culprit) then I sometimes end up with two items selected at once, although the grid selectionMode attribute is set to single.

Any thoughts on this one?

Thanks a lot.

2

2 Answers

0
votes

You need to use setSelected(), like so

exportMappingGrid.selection.setSelected(newItemIndex, true);

The second parameter is true to select the row, false to unselect it.

0
votes

This is what works for me:

grid.selection.clear();
grid.selection.addToSelection(newItemIndex);
grid.selection.getFirstSelected();

Jon