Refresh single ExtJs grid row after editing without refreshing grid

Hello,

This is another ExtJs blog. Recently I was working with ExtJs editor grid and I got requirement that after editing data in a row grid should be refreshed and at the same time row should be back to its normal position.
Those who have worked with ExtJs editor grid know that when you edit values in row cells, it will display red mark on top left corner. It states that row data is edited. See the image below.

To remove it, we need to reload grid data and refresh the grid view. Following is the code for it.
myGrid.store.reload();
myGrid.getView().refresh();
Grid will be refreshed and updated data gets loaded from server. Now my requirement was to refresh the only single row, without refreshing the whole grid. When you tab out of edit field or you click outside of the row it will fire afteredit event. Normally in afteredit event there is a Ajax request to send updated data to server and when we get success response we normally reload the grid data store. But in this case its different situation. Following is the code for it.
‘afteredit’:{
fn : function(e){
Ext.Ajax.request({
url:”savedata.php”,
method:’GET’,
params:{
param1:value1,
param2:value2
},
success:function(resp,opt){
e.record.set(e.field,gridValue);
e.record.commit();
myGrid.getView().refresh();
},
failure:function(resp,opt){
}
});
}
}
Checkout the code in success function of Ajax request. This does the trick.
e.reocord.set() function set’s the value. For example if you have some renderer for columns then this code will set the cell value according to renderer.
e.record.commit() commits the changes and grid row is back to its normal view. It will remove all the red marks from the edited cell.
So using this small trick you have normal row after editing it without refresh the grid data. This trick is useful when you have large number of data in the grid and you want to avoid unnecessary data flow.


This entry was posted in ExtJs, ExtJs editor grid, Refresh row on by .

About Hiren Dave

Hiren Dave is a software engineer, blogger and consultant with over 9 years of professional experience. He writes code in number of languages. Hiren has a passion for developing web apps, mobile apps and writing books and blog articles about programming. He has a solid experience of startups as he manages products for few startups. He is also passionate about researching and learning new technologies and trends. He has also authored a book Instant Sencha Touch, published by Packt and creator of Video Course "Beginning Laravel" for Packt

12 thoughts on “Refresh single ExtJs grid row after editing without refreshing grid”

  1. Hiren

    Well I am not sure as in native ExtJs library no repeater controls are available. Its available in Ext.Net which is specifically build for Asp.Net by integrating ExtJs. I only work with native ExtJs but I will look into it and post it here.

    Reply ↓
  2. Anonymous

    The only problem I see with the code is that you are not testing the ajax response to see if the information was actually saved to db or not. A success response in a ajax function only means that a exchange of info took place ok. It does not mean that whatever it is you where trying to do actually worked. You need to test with something like:

    Reply ↓
  3. nomadz

    I have a situation here. I implemented a combo box for Pagination number expansion. I want to dynamically refresh the page on select the combo box value. Can u please help me with this?. The code is below. I tried reload and refresh button I have no idea why they are not working inside my code.

    combo.on('select', function(combo, record) {
    bbar.pageSize = parseInt(record.get('id'), 10);
    bbar.doLoad(bbar.cursor);
    }, this);

    Reply ↓

Leave a Reply

Your email address will not be published. Required fields are marked *