PDA

View Full Version : Ext.ux.data.JsonArrayReader..use arrays for paging grids!



wm003
18 Apr 2008, 2:50 AM
I (and others too...) had the need to use an ArrayReader but also the possibility to gain the totalproperty-config option for grid paging.

Well, just use the following Ext.ux.data.JsonArrayReader.;) It works exactly like JsonReader, but performs on Arrays instead of a jsonstore..~o)

Usage Example:



var myreader = new Ext.ux.data.JsonArrayReader({
totalProperty: 'allentries',
root:'rows'
}, [
{name: 'uid', type: 'float'},
{name: 'external_id'},
{name: 'birthday', type: 'date', dateFormat: 'Ymd'},
{name: 'status'},
{name: 'minutes'}
]);
This would consume a returned object of the form:



{
"allentries":4,
"rows":[
[265,"0000811645690010","19700101","S",60],
[266,"0000811645700010","19700101","S",60],
[267,"0000811645710010","19700101","S",60],
[268,"0000811645720010","19700101","S",60]
]
}

mlarese
18 Apr 2008, 3:57 AM
but why json. You read an array.

wm003
18 Apr 2008, 4:43 AM
but why json. You read an array.

Only the grid-data comes as an array. the whole string (with the config items for totalproperty , etc..) come as objects, so altogether you still have a Json-String. only difference to the original jsonsreader is the fact, the grid data is expected in an array and not (again) as json.

That was the problem with the original arrayreader, it expected the _whole string_ as an array, thus wont made it possible to give additional config items.

mabello
18 Apr 2008, 6:32 AM
Good job.

I had the same problem and I solved in a different way, but I think that this extension is more neat than my way.

I had changed the ArrayReader (override the read method) so that you could pre and post process your data to gain the totalproperty-config option for grid paging etc

Check out this thread about a discussion on DataReader:

http://extjs.com/forum/showthread.php?t=31347

Thanks again and well done

Tuom Larsen
14 Jul 2008, 4:26 PM
Wonderful! Thanks a lot!

sami_user
17 Jul 2008, 7:20 AM
I (and others too...) had the need to use an ArrayReader but also the possibility to gain the totalproperty-config option for grid paging.

Well, just use the following Ext.ux.data.JsonArrayReader.;) It works exactly like JsonReader, but performs on Arrays instead of a jsonstore..~o)

Usage Example:



var myreader = new Ext.ux.data.JsonArrayReader({
totalProperty: 'allentries',
root:'rows'
}, [
{name: 'uid', type: 'float'},
{name: 'external_id'},
{name: 'birthday', type: 'date', dateFormat: 'Ymd'},
{name: 'status'},
{name: 'minutes'}
]);
This would consume a returned object of the form:



{
"allentries":4,
"rows":[
[265,"0000811645690010","19700101","S",60],
[266,"0000811645700010","19700101","S",60],
[267,"0000811645710010","19700101","S",60],
[268,"0000811645720010","19700101","S",60]
]
}




Thanks - I am not able to open the zip file containing your souce code. Its says that the archive is corrupted. Can you please repost the file please.

Regards,
Sam

mystix
17 Jul 2008, 7:33 AM
Thanks - I am not able to open the zip file containing your souce code. Its says that the archive is corrupted. Can you please repost the file please.

Regards,
Sam
download using Firefox. IE has been crapping out with this forum's attachments of late.

krause
17 Sep 2008, 3:14 PM
This is exactly what I was looking for. I't not only seems more efficient network-wise (no need to transfer the property names for each record) but it is also easier to create "on the fly" server side objects, at least in strong typed programming languages as Java and C# which requires a concrete class to represent the rows.
I'll give it a try.

Any possible drawbacks anyone can see?
Any new & improved version of this?

Condor
18 Sep 2008, 4:16 AM
Wouldn't it be easier to use:


var myreader = new Ext.data.JsonReader({
totalProperty: 'allentries',
root:'rows'
}, [
{name: 'uid', type: 'float', mapping: '0'},
{name: 'external_id', mapping: '1'},
{name: 'birthday', type: 'date', dateFormat: 'Ymd', mapping: '2'},
{name: 'status', mapping: '3'},
{name: 'minutes', mapping: '4'}
]);

(no need for a user extension at all)

krause
18 Sep 2008, 8:40 AM
You are absolutely right, JsonReader works just fine using the mapping property.
Thanks for your reply.