How to clear the grid in Extjs
Asked Answered
A

3

6

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.

Amadeus answered 24/7, 2013 at 11:17 Comment(1)
I wouldn't use the forceFit option in the view. It's recommended to use flex on the grid itself. (not related to your issue but it's a suggestion)Tedmund
S
17

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!

Sharpen answered 24/7, 2013 at 11:37 Comment(1)
Don't forget to refresh the grid when store is cleared. If you don't do that, strange behaviour may happen. grid.view.refresh()Dormie
B
0

This worked for me:

Ext.ComponentQuery.query('#yourGrid')[0].getStore().removeAll();

Hope it helps.

Brindle answered 16/7, 2014 at 16:42 Comment(0)
A
0

var usrStore = Ext.StoreManager.lookup('LES.ossi.ossi-sampleapp.store.MainStore');

usrStore.removeAll();

Ahmadahmar answered 15/9, 2022 at 9:44 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Noria

© 2022 - 2024 — McMap. All rights reserved.