PDA

View Full Version : Updating a Grid's row



sajan
24 Aug 2011, 9:56 PM
Hi all,
I have a grid.
Double clicking on a grid will open up a new window where I can make some modifications on the record.
So after I click OK on the window it should also update the values on the grid.
I can reload the store but this is not the correct way of doing it.
SO please help me updating/modifying a record on a grid.
thanks in advance.

raz0r1
25 Aug 2011, 3:12 AM
do you save the changes you make in the window directly to the store?

if yes try a

grid.getView().refresh();

if not you have to reload the store.

sajan
25 Aug 2011, 4:11 AM
Hi I am not directly working on grid data.
So the saves are not directly to the store
So please help me if possible
thanks

raz0r1
25 Aug 2011, 8:46 AM
ok.
you have to provide more info
- how you change the data
- what do you do with the changed data

if i assume that you edit the data via a formpanel and than save it do the database you have to reload the store. or you change the record that you changed via the formpanel directly in the store.

please give more info.

sajan
25 Aug 2011, 8:58 AM
you change the record that you changed via the formpanel directly in the store.

Yes I want this. I want to change the record directly to the store

so please do help me how to do this.

thanks

raz0r1
25 Aug 2011, 12:11 PM
if you give the code of your form panel it would be easier.
in gerneral you have to do something like this:


submitbutton.on('click', function(button) {
var form = btn.up('formpanel');
var formfields =form.getFieldValues();
var recordToUpdate = form.getRecord();
for(key in formfields)
{
recordToUpdate.set(key, formfield[key]);
}
});


i think this should work (its untested) but i am quite sure that there is a more elegant way to do this. (the solution above is quick'n'durty i think)

please check out on your own the following classes (this are the classes you need to do what you want):
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic
(http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic)http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model
(http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model)http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store


further: way you dont use an editor grid? check out:
http://docs.sencha.com/ext-js/4-0/#!/example/grid/row-editing.html
http://docs.sencha.com/ext-js/4-0/#!/example/grid/cell-editing.html
i (http://docs.sencha.com/ext-js/4-0/#!/example/grid/cell-editing.html) think the first one fits your requirements. (this is much easier to use then the way you posted above)

please give short feedback if that solves your problem.