PDA

View Full Version : easy way to convert an Ext.data.JsonStore into JSON object?



xava
24 Aug 2009, 3:25 PM
hello!

my code is:


__fGrid= new Ext.grid.GridPanel({
ddGroup: 'firstGridDDGroup'
,store: new Ext.data.JsonStore({
fields: [{
name: 'id_distinguible',
mapping: 'id_distinguible'
}, {
name: 'distinguible',
mapping: 'distinguible'
}],
root: 'records',
autoSave: true
})
,reader: new Ext.data.JsonReader({
root: 'records',
totalProperty: 'totalRecords'
}, [{
name: 'id_distinguible',
mapping: 'id_distinguible'
}, {
name: 'distinguible',
mapping: 'distinguible'
}])
,cm: new Ext.grid.ColumnModel([
{header: '#', dataIndex: 'id_distinguibles', hidden: true},
{id: 'distinguible', header: 'Distinguible', dataIndex: 'distinguible' ,width: 50}
])
,height: 200
,width: '98%'
,enableColumnHide: false
,enableHdMenu: false
,enableDragDrop: true
,stripeRows: true
,autoExpandColumn: 'distinguible'
});

and store data is load from to grid on this event



[...]
,onSelect: function(record){
var records = new Array(); records.push(record);
_fGridDistinguibles.store.add(records);
_fGridDistinguibles.store.sort('name', 'ASC');
}
[..]
i get and json object to send a AJAX server, but _fGrid.store.jsonData not working

any idea?

thanks!

VinylFox
24 Aug 2009, 6:36 PM
jsonData is a property of the reader...


store.reader.jsonData

xava
24 Aug 2009, 6:46 PM
jsonData is a property of the reader...


store.reader.jsonData

thanks, this don't work! :1 but, if i use store.getAt(item_index) work :s

VinylFox
26 Aug 2009, 12:38 PM
Your response makes no sense at all.

You asked how to get the JSON object, however the code you posted as a 'fix' retrieves a record.

hendricd
27 Aug 2009, 9:38 AM
Could be something as simple as:



var recs = [];
store.each(function(rec){ recs.push(rec.data); });
var payLoad = {
total : recs.length,
records : recs
}
var toSend = Ext.encode(payLoad);

Tweak to suite what your server needs.