arcgis 10.2 how to order query results

4668
7
Jump to solution
06-23-2015 04:31 PM
davidzornosa
New Contributor III

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

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

David,

   You can not just add an order by to the where. You need to use the orderByFields property of the Query.

Query | API Reference | ArcGIS API for JavaScript

View solution in original post

7 Replies
XanderBakker
Esri Esteemed Contributor

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.

XanderBakker
Esri Esteemed Contributor

BTW: this is the page where you can consult the GeoNet Community Structure

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

David,

   You can not just add an order by to the where. You need to use the orderByFields property of the Query.

Query | API Reference | ArcGIS API for JavaScript

XanderBakker
Esri Esteemed Contributor

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..

OwenEarley
Occasional Contributor III

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.

ChrisSmith7
Frequent Contributor

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!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos