Is there a method allowing me to return my stored data in an ExtJS Grid Panel exactly the way I loaded it using:
var data = [\"value1\", \"value2\"]
Store.lo
A simple way to do this is
var jsonArray = store.data.items
So if your JSON store is
[{"text": "ABC"}, {"text": "DEF"},{"text": "GHI"},{"text": "JKL"}]
Then you can retreive "DEF" as
jsonArray[1].data.text
In the following code, I noticed that it converts each and every character into an array item.
var jsonData = Ext.encode(Ext.pluck(store.data.items, 'data'));
A one-line approach:
var jsonData = Ext.encode(Ext.pluck(store.data.items, 'data'));
Not very pretty, but quite short.
function getJsonOfStore(store){
var datar = new Array();
var jsonDataEncode = "";
var records = store.getRange();
for (var i = 0; i < records.length; i++) {
datar.push(records[i].data);
}
jsonDataEncode = Ext.util.JSON.encode(datar);
return jsonDataEncode;
}
A better (IMO) one-line approach, works on ExtJS 4, not sure about 3:
store.proxy.reader.jsonData
In my case I wanted a javascript jagged array e.g. [["row1Cell1", "row1cell2"],["row2Cell1", "row2cell2"]] based on the contents of the Ext grid store.
The javascript as below will create such an array, dropping the id key in the object which I didn't need.
var tableDataArray = [];
Ext.ComponentQuery.query('[name="table1"]')[0].store.each(function(record){
var thisRecordArray = [];
for (var key in record.data) {
if (key != 'id') {
thisRecordArray.push(record.data[key]);
}
}
tableDataArray.push(thisRecordArray);
});
As suggested above I tried below one with fail.
store.proxy.reader.jsonData
But below one worked for me
store.proxy.reader.rawData