How to clear the grid in Extjs

Java Learner picture Java Learner · Jul 24, 2013 · Viewed 19.6k times · Source

I have a GridStore in Extjs which can store records with two grid columns. I have a problem when one record exists in Grid, if i delete the grid its been deleted successfully in server side, but that still exists in Grid.

Sample code:

    xtype: 'grid',
    store: 'SampleStore',
    border: false,
    width : 542,
    ref: '../sampleGrid',
    id: 'sampleGrid',
    columns: [
       {
       xtype: 'gridcolumn',
       dataIndex: 'name',
       header: 'Name',
       sortable: true,
   .............
    view: new Ext.grid.GridView({
    forceFit: true
    })

Thanks for help in advance.

Answer

Mike picture Mike · Jul 24, 2013

Make sure you are using:

grid.getStore().remove(record); //remove record from grid
grid.getStore().sync(); //sync with server

If you want to remove all items, do:

grid.getStore().removeAll();
grid.getStore().sync();

But be careful! That will delete everything!