PDA

View Full Version : Remove Item from Edit Grid



Preston85
21 Aug 2009, 12:55 AM
Just attempting a "simple" remove from a edit grid.

The button:

{
text: 'Remove Address',
handler: function(){
var sm = Ext.getCmp('address_edit_grid').getSelectionModel();
var sel = sm.getSelected();
if (sel.hasSelection()) {
var conn = new Ext.data.Connection();
conn.request({
url: './company/assets/fnc/address_update.php',
params: {
action: 'Delete',
id: e.record.idaddressdetails
},
success: function(resp,opt) {
grid.getStore().remove(sel);
},
failure: function(resp,opt) {
Ext.Msg.alert('Error','Unable to delete');
}
});
}
}
}

The error

sm.getSelected is not a function
chrome://firebug/content/blank.gif var sel = sm.getSelected();\r\n

This code basically came from Edit Grid section in the Learning Ext book so no idea why it shouldn't work.

evant
21 Aug 2009, 1:24 AM
My guess would be because edit grids usually have a CellSelectionModel, which doesn't have a getSelected method.

Preston85
21 Aug 2009, 1:34 AM
Thats what I thought but since he published it with that code I thought it might recognize what row the cell selection is made and use that for the row selection.

Point me in the correct direction please? Is it possible to do in a Edit Grid or do I have to change to a row edit grid or something else?

Thanks.

evant
21 Aug 2009, 1:42 AM
Um, something like:



var sel = sm.getSelectedCell();
if(sel){
// sel now contains an array of [row, col]
}

Preston85
21 Aug 2009, 1:59 AM
Thanks, should get it working now.

Preston85
21 Aug 2009, 2:54 AM
Wasn't as simple as I expected. I thought i'd be able to do sel.record.id to reference the rows id column but I get an error that record is undefined.

How do I directly reference the contents of a cell from a grid to use?

Preston85
25 Aug 2009, 1:17 AM
Any guidance here guys? I've checked around to see if I can find how you use row/cell to access a grids data but can't find anything so am at a dead stop.

Animal
25 Aug 2009, 1:23 AM
What's the prob?

You got the row index from the selection object, so that's it, get the Record at that index in the Store.

evant
25 Aug 2009, 1:23 AM
The items in the store are the same order as in the grid:



var sel = sm.getSelectedCell();
if(sel){
var rec = myGrid.getStore().getAt(row);
}