1. #1
    Sencha User
    Join Date
    Nov 2009
    Posts
    58
    Vote Rating
    -1
    emils is on a distinguished road

      0  

    Default Answered: 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:
    Code:
    	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!

  2. Commit is alive and well:

    http://docs.sencha.com/ext-js/4-0/#!...-method-commit

    Don't manipulate the record's data property directly, use set instead:

    Code:
    record.set('TYPE', obj.data.TYPE);
    record.set('PURPOSE', obj.data.PURPOSE);
    
    record.commit();
    or :

    Code:
    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.

  3. #2
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    657
    Vote Rating
    39
    Answers
    21
    vadimv has a spectacular aura about vadimv has a spectacular aura about

      0  

  4. #3
    Sencha User
    Join Date
    Nov 2009
    Posts
    58
    Vote Rating
    -1
    emils is on a distinguished road

      0  

    Default

    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!

  5. #4
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    657
    Vote Rating
    39
    Answers
    21
    vadimv has a spectacular aura about vadimv has a spectacular aura about

      0  

    Default

    from the docs:
    Code:
    var sel = grid.getSelectionModel( ).getSelection( );
    sel[0].commit();

  6. #5
    Sencha User
    Join Date
    Nov 2009
    Posts
    58
    Vote Rating
    -1
    emils is on a distinguished road

      0  

    Default

    But is not work for me...
    Code:
    	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...

  7. #6
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    657
    Vote Rating
    39
    Answers
    21
    vadimv has a spectacular aura about vadimv has a spectacular aura about

      0  

    Default

    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']....

  8. #7
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,786
    Vote Rating
    379
    Answers
    581
    skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute

      0  

    Default

    Commit is alive and well:

    http://docs.sencha.com/ext-js/4-0/#!...-method-commit

    Don't manipulate the record's data property directly, use set instead:

    Code:
    record.set('TYPE', obj.data.TYPE);
    record.set('PURPOSE', obj.data.PURPOSE);
    
    record.commit();
    or :

    Code:
    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.

  9. #8
    Sencha User
    Join Date
    Nov 2009
    Posts
    58
    Vote Rating
    -1
    emils is on a distinguished road

      0  

    Default

    Thank you for answers!

    Actaly i`ve used this:
    Code:
    	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

Thread Participants: 2