Dojo DataGrid to load selected items

I have a DataGrid and you want the user to select multiple items and click a button to do something with those items (eg delete). When only a few items are selected, the deletion is performed, but if the user selects all items without slowly scrolling over them, some of the selected items are zero.

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

I tried it 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 when fetching, there are still zero elements and in fact only the top-most and bottom-most rows are removed.

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

+2


source to share


1 answer


My task was to "expand" the selection of the values ​​of the first element to the rest of the selection. I faced a 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 that, you should connect this function to the button in addOnLoad:

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

      

+1


source







All Articles