Hi
Is there a way to order the returned results of a query task?
this:
query.where = "COD > 0";
works fine, but this:
query.where = "COD > 0 order by COD";
throws:
dojo.io.script error undefined
Please note that our server has standardized queries enabled and we cannot change that.
Thanks
Solved! Go to Solution.
David,
You can not just add an order by to the where. You need to use the orderByFields property of the Query.
Hi david zornosa ,
Could you move this thread to the ArcGIS API for JavaScript place. You will get better answer in that space.
See: Moving Content
GeoNet Help is for help on using GeoNet only.
BTW: this is the page where you can consult the GeoNet Community Structure
David,
You can not just add an order by to the where. You need to use the orderByFields property of the Query.
And now something on topic. Maybe this link will help Query | API Reference | ArcGIS API for JavaScript . There is a orderByFields property that you could use (I think).
edit: ...and I should have known that Robert would beat me to it..
You could use client side sorting for this - see this quick demo I put together: QueryTask - client side sorting
Basically, you just use the array.sort method with an anonymous function:
results.features.sort(function(a, b) { // return a.attributes.POP2007 - b.attributes.POP2007; // ascending return b.attributes.POP2007 - a.attributes.POP2007; // descending });
In your case replace the POP2007 field name with COD to sort the features.
Like others mentioned, you could use orderByFields, or client-side sorting. However, I bet it would work if you turned-off standardized queries and used a subquery for the where clause (that contained an ORDER BY). Note that I would NOT recommend doing this!
david zornosa Did these replies help you? If so then please make this question as Answered. And if you that that a reply was helpful then click the helpful link on that post.