PDA

View Full Version : How to get data from GridPanel



zalol
17 Aug 2011, 4:29 PM
Hi All,


I am trying to to get the data from GridPanel. I tried to use grid.getSelections(), but FireBug is complaining that it is not a function.

I am new to EXTJS so if anyone knows how to solve this, please help.


Thanks.

Zalol.

Update:
Apologies. Looks like I made a post in EXTJS 4. Can you please move it from here. I am using EXTJS 3.4

raz0r1
17 Aug 2011, 10:30 PM
You have to specify a little:
do you want to get the selected records or do you want to get all records?

If you want to get the selected records, use:



var selModel = panel.getSelectionModel();
var selectedRecords = selModel.getSelection();
var selectionCount = selModel.getCount();
for(var i =0;i<selectionCount;i++) {
console.log(selectedRecords[i]);
}


This logs the underlying storerecord of the selected row to your firebug console.

HTK
17 Aug 2011, 11:17 PM
This is really a bit general, but I maybe this helps:

grid.getView().getSelectionModel().getSelection()[0]
grid.getView().getSelectedRecords()

I guess what you are searching is in the view class.

zalol
18 Aug 2011, 11:03 AM
Thanks for the reply guys.


Sorry for not being specific on my question. What I am looking to do is to get all the records from the Grid.

skirtle
18 Aug 2011, 5:17 PM
Sorry for not being specific on my question. What I am looking to do is to get all the records from the Grid.

So you want all of them, not just the selected ones? The records all live in a store. Essentially the store is 'all the records'. You haven't said exactly what form you want the records in or how you intend to use them. You have several methods available to you on the store, including each() for iterating over them.


grid.getStore().each(function(record) {
...
});

raz0r1
18 Aug 2011, 9:50 PM
if you only want an array of all data you can use


grid.getStore().data.items


http://docs.sencha.com/ext-js/4-0/#/api/Ext.data.Store-property-data

if you want to search for a specific record(s), you can usee


grid.getStore().data.filter(propertyKey, valueToSearchFor);


http://docs.sencha.com/ext-js/4-0/#/api/Ext.util.MixedCollection-method-filter

h (http://docs.sencha.com/ext-js/4-0/#/api/Ext.util.MixedCollection-method-filter)ope that helps.

mikhailt
19 Aug 2011, 4:15 AM
Depends on your proxy settings.
In case of local memory proxy I use
grid.getStore().getProxy().data

In case of remote proxy you need to retrieve date remotely I guess.

Ixtinkt
26 Feb 2013, 2:04 AM
ExtJs 4.0.2a


var element_id; // view id of record.
grid.getStore().data.map[element_id].data;