PDA

View Full Version : Removing a row from an EditorGridPanel



Thomas Triplet
18 Jun 2009, 12:04 PM
Hi,
I'm working with an EditorGridPanel, and I need to add and remove rows (from buttons in the toolbar).

Adding rows is pretty straight forward and is working fine:


text:'Add',
tooltip:'Add a new row',
iconCls:'add',
handler: function() {
var p = new Primer();
spreadsheet_panel.stopEditing();
spreadsheet_store.insert(0,p);
spreadsheet_panel.startEditing(0, 0);
}


But I can get the Delete button to work: nothing happens basically, no error in the Javascript from the debugger, it just looks like the editorgrid needs to be refreshed, but I couldn't find my way around (I'm new to Extjs...)



text:'Remove',
tooltip:'Remove the selected item',
iconCls:'remove',
handler: function () {
spreadsheet_panel.stopEditing();
var xySelected = spreadsheet_panel.getSelectionModel().getSelectedCell();
spreadsheet_store.remove(xySelected[0]);
}


Thanks a lot for your help

pavanextjs
18 Jun 2009, 2:50 PM
We need to get the selected Row, not the selected Cell.

Try this...


text:'Remove',
tooltip:'Remove the selected item',
iconCls:'remove',
handler: function () {
spreadsheet_panel.stopEditing();
var xySelected = spreadsheet_panel.getSelectionModel().getSelected();
spreadsheet_store.remove(xySelected[0]);
}

mjlecomte
18 Jun 2009, 7:22 PM
technically you want to get at the records in these cases. You add a record or remove a record to/from the store.

Thomas Triplet
19 Jun 2009, 6:16 AM
We need to get the selected Row, not the selected Cell.

Try this...


text:'Remove',
tooltip:'Remove the selected item',
iconCls:'remove',
handler: function () {
spreadsheet_panel.stopEditing();
var xySelected = spreadsheet_panel.getSelectionModel().getSelected();
spreadsheet_store.remove(xySelected[0]);
}

Ys I tried that before, but I am using an EditorGrid, nor a regular Grid, so there are no such method implemented.

Object [object Object] has no method 'getSelected'

Also, xySelected[0] returns me the correct row number, but
spreadsheet_store.remove(xySelected[0]) doesn't seem to have any effect

@mjlecomte I'm not sure to get what you mean, I indeed would like to remove a Record, but I would also like to see the change in the table which is displayed, not just in the underlying store

19 Jun 2009, 6:23 AM
See the following Example from chapter 8 of ExtJsInAction (http://maning.com/garcia)

http://tdg-i.com/extjsinaction/chapter08/Editor_panel_with_manual_saves.html

mjlecomte
19 Jun 2009, 6:25 AM
The grid monitors (listens to) the datachange event of store. So if you add/remove records from the store the grid will react to it.

You have selected something within the grid. You use the selection model, one of its methods, to get at the record from that selection. Once you have the record then you can do what you want with it (remove from store in your case).

The selection model select methods are not uniform unfortunately (I have a feature request in to request it be normalized). So you have to use the method appropriate to the model.

Thomas Triplet
19 Jun 2009, 6:36 AM
@garcia: the links don't seem to work (Error 404 in Korean for the first one, the second one keeps loading)

Hey, I found it, I needed to use store.removeAt() instead of store.remove()

Thanks the the help :)

19 Jun 2009, 7:14 AM
Yeah, i need to fix that. ;)