View Full Version : How to replace grid row (record) with new values ?
Hello,
In Extjs 3, when my form is submited succesful, i am using this code to replace selected record in grid with the new one:
aForm.getForm().submit( {
url: aForm.url,
scope: this,
method:'POST',
........
success: function(form, action) {
var obj = Ext.util.JSON.decode(action.response.responseText);
if (obj.success == 'true') {
var SelectedRec = Ext.getCmp('gridNalST').getSelectionModel().getSelected();
SelectedRec.data['field1'] = obj.data.field1;
SelectedRec.data['field2'] = obj.data.field2;
...........
SelectedRec.commit();
There is no function SelectedRec.commit() in Extjs 4 :(
How to change my code to works fine ?
Thanks!
vadimv
9 Dec 2011, 6:23 AM
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model
Of course I have read the documentation and i know the changes in version 4 ...If I find information on the API docs i would not write here!
vadimv
9 Dec 2011, 6:45 AM
from the docs:
var sel = grid.getSelectionModel (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.panel.Table-method-getSelectionModel)( ).getSelection (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.selection.Model-method-getSelection)( );
sel[0].commit (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model-method-commit)();
But is not work for me...
var SelectedRec = Ext.getCmp("grid-Armeec").getSelectionModel().getSelection();
SelectedRec[0]['TYPE'] = obj.data.TYPE;
SelectedRec[0]['PURPOSE'] = obj.data.PURPOSE;
SelectedRec[0].commit();
Looks ok, no error messages, but NOT change values in the grid...
vadimv
9 Dec 2011, 7:10 AM
So this is the second question, just tried in my app, it works, but looking at your code I see no SelectedRec[0].data['TYPE']....
skirtle
9 Dec 2011, 8:13 AM
Commit is alive and well:
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model-method-commit
Don't manipulate the record's data property directly, use set instead:
record.set('TYPE', obj.data.TYPE);
record.set('PURPOSE', obj.data.PURPOSE);
record.commit();
or :
record.set({
TYPE: obj.data.TYPE,
PURPOSE: obj.data.PURPOSE
});
record.commit();
The call to commit is required to get rid of the dirty flag, it isn't required to update the grid with the new values.
emils
10 Dec 2011, 1:15 AM
Thank you for answers!
Actaly i`ve used this:
var SelectedRec = Ext.getCmp("grid").getSelectionModel().getSelection();
SelectedRec[0].beginEdit();
Ext.getCmp("form").getForm().updateRecord(SelectedRec[0]);
SelectedRec[0].endEdit;
and it works... But now there is another ploblem :)
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.