views:

1315

answers:

1

I have a DataGrid and want a user to select multiple items and click a button to do something with those items (such as delete). When only a few items are selected, the deleting works, but if the user selects all the items without scrolling slowly over them, some of the selected items are null.

I also tried grid.removeSelectedRows(), but that also doesn't work for non-loaded items.

I tried fetching first, too:

grid.store.fetch({count:grid.rowCount,onComplete:dojo.hitch(this,function(){
  var items = grid.selection.getSelected();
  grid.selection.clear();
  if (items.length) {
    dojo.forEach(items, function(selectedItem) {
      if (selectedItem !== null) {
        grid.store.deleteItem(selectedItem); //or do something else
      }
    });
  }
  grid.sort();
})});

Even with the fetch, there are still null items, and only the very top and bottom rows actually get deleted.

Is there a way to load the selected items in a grid?

+1  A: 

My task was to "extend" selection first item values to the rest of the selection. I've faced similar problem as yours, but finally found a solution:

updateSelected = function() {

//Callback for processing a returned list of items.
function gotSelected(items, request) {
 var selectedIndex = paramGrid.selection.selected;
 console.debug(selectedIndex);
 var firstItem;
 var counter = 0;
 for (var i=0;i<selectedIndex.length;i++){
  if(selectedIndex[i]){
   var item = items[i];
   if (counter < 1){
    firstItem = item;
    counter ++;
   }else{               
    paramStore.setValue(item, "valueSPO", firstItem.valueSPO);
    paramStore.setValue(item, "valueSPI", firstItem.valueSPI);
    paramStore.setValue(item, "valueSM", firstItem.valueSM);
    paramStore.setValue(item, "state", firstItem.state);
   }
  }
 }        
}

function fetchFailed(error, request) {
    console.log("lookup failed.");
    console.log(error);
}

paramStore.fetch({
    query: {id: '*'},
    onComplete: gotSelected,
    onError: fetchFailed,
});

}

After this you have to connect this function to a button in addOnLoad:

dojo.connect(button2, "onClick", updateSelected);
Attila Kiss