简体   繁体   中英

Extjs4 save all grid data in a table

I know how to get a value from a selected row of a grid, just like this:

var records = Ext.getCmp('My_Grid').getSelectionModel().getSelection();
var record  = records.length === 1 ? records[0] : null;
alert(record.get('name'));

But what I want is to get the name of all rows of the grid. To do it, I have used the method above, to write this functional function:

var MonTableau = new Array();
for (var j=0; j<=Ext.getCmp('My_Grid').getStore().getCount()-1; j++) {
Ext.getCmp('My_Grid').getView().select(j);
var records = Ext.getCmp('My_Grid').getSelectionModel().getSelection();
var record  = records.length === 1 ? records[0] : null;
MonTableau[j+1]=record.get('name');
                }

But it's not professional, I want more simple and professional method.

The ExtJS store provides an each function which applies a passed fn for each record cached (already loaded) in the store:

var myStore = Ext.getCmp('My_Grid').getStore();
myStore.each(function(rec) {
    console.log(rec.get('name'));
});

PS I'm using console.log(); rather than alert(); as I think it's easier to read everything from the browser log.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM