PDA

View Full Version : More EditorGridPanel questions...



rbastic
20 Jul 2009, 7:34 AM
Hi,
I've been trying to figure out how to implement a "delete row" button for an EditorGridPanel...

But the following code doesn't work:



{
ref: '../removeBtn',
text: 'Delete',

handler : function() {

//var selected = grid.getCellSelectionModel().getSelections();
var selected = grid.getSelectionModel().getSelections();

var n = selected.length;
if (n > 0)
{
//specify a refresh limit to control whether the entire
//grid is updated or just update rows individually
//it may be beneficial to update entire view if number
//of selections are high
var refreshLimit = 5; // you decide

//suspend the Grid's events and resume after tasks completed
//(helps with performance, otherwise would be much slower)
grid.suspendEvents();

//get the store associated with the grid:
var store = grid.getStore();

//loop through each record and delete
for(var i=0; i < selected.length; i++){
//remove record from the cache
store.remove(selected[i]);//record = selected[i]

//refresh row if under limit
if (n <= refreshLimit) {
store.fireEvent("update", store, selected[i],
Ext.data.Record.COMMIT);
}
}

//turn events back on now that the work has been done
grid.resumeEvents();

//since events were disabled, gridView does not know that the
//data has changed. We turned events back on, but we need to
//manually fire the datachanged event to refresh entire grid
if (n > 5) {
store.fireEvent("datachanged", store);
}
}
else
{
//show message box?
return false;
}
}
},



I pulled this code from the ExtJS docs. Specifically, the getSelectionModel() is apparently breaking and returning nothing. My editor is apparently in cell selection mode, though -- I'm not aware of how to change it specifically. Things like the selModel property are read-only..

So, I've read the docs that I can find on this issue, and nothing's helping. What have people done to solve this before?