Opened 11 years ago

Closed 11 years ago

#9286 closed enhancement (wontfix)

XmlStore should implement typeMap

Reported by: Rob Retchless Owned by: Jared Jurkiewicz
Priority: high Milestone: tbd
Component: DojoX Data Version: 1.3.0
Keywords: Cc:
Blocked By: Blocking:

Description

I'm looking for a way to sort the output of my XML store by date. As far as I can tell, there's no easy way to do this.

ItemFileReadStore? takes a typeMap parameter which maps fields to data types. This should be added to XmlStore?.

Change History (3)

comment:1 Changed 11 years ago by Adam Peller

Component: GeneralDojoX Data
Owner: changed from anonymous to Jared Jurkiewicz

comment:2 Changed 11 years ago by Jared Jurkiewicz

Patches are welcome. Feel free to provide one. :-)

comment:3 Changed 11 years ago by Jared Jurkiewicz

Resolution: wontfix
Status: newclosed

After more thought, this doesn't make sense ofr XML store.

TypeMap? works with JSON and JSON type items and stuctures. XMLStore is access to XML data, which are either nodes or strings. The XmlStore? is designed to work with general XML, so by trying to enforce a 'typeMap', you end up removing its general nature.

The problem that triggered this request, though, is easily solvable with the current XML store implementation.

XmlStore? mixes in dojo.data.util.simpleFetch, which implements the fetch function. The fetch function makes use of dojo.data.util.sorter to do the sort.

This means you have access to defining a custom sort function (See ItemFileStore? docs about custom sorting. Same concept applies here):

http://docs.dojocampus.org/dojo/data/ItemFileReadStore#custom-sorting

You can define a sort function for particular attributes of your XML. In this sort function you cna treat atttributes as dates or whatever you want. Effectively, to create sort function that would treat an attribute 'date' as a Date style sort, all you would do is:

var xStore = new dojox.data.XmlStore?(<whatever>);

xStore.comparatorMapmyDateAttr? = function( /*anything*/ a,

/*anything*/ b){

summary: Comparator function that treats the contents of an attribute as a Date description: returns 1 if a > b, -1 if a < b, 0 if equal. 'null' values (null, undefined) are treated as larger values so that they're pushed to the end of the list. And compared to each other, null is equivalent to undefined.

if(a){a = dojo.date.stamp.fromISOString(a.toString());} if(b){b = dojo.date.stamp.fromISOString(b.toString());} var r = -1; if(a === null){

a = undefined;

} if(b === null){

b = undefined;

} if(a == b){

r = 0;

}else if(a > b
a == null){

r = 1;

} return r; int {-1,0,1}

};

Then when you ask the store to sort on that attribute, it will try to treat it like a date.

Note: See TracTickets for help on using tickets.