<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Sorting attribute table in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260249#M24084</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Samir&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think what they mean "dynamic layers" as a property of the service.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;NOTE: this is a property of the ArcGIS REST Services Directory for your MapService&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Supports Dynamic Layers: true&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not too sure if this is the correct way for you to follow.&amp;nbsp; I just tried implementing what you are trying to do and had no success. However, in my case, the queries ran correctly with no errors but the featureSet was not "ordered by" the field that I indicated.&amp;nbsp; Sometimes it would actually change my result set based on OBJECTID ASC or DESC order (which I had indicted in the orderByFields param) but it NEVER sorted by the field that I indicated.&amp;nbsp; I am not sure if I was implementing it correctly&amp;nbsp; ... but my results were inconclusive.&amp;nbsp; I tried it with both a featureLayer.selectFeatures and an MapService URL via a QueryTask.execute.&amp;nbsp; No luck.&amp;nbsp; Sorry, I wish I could be more of help but I am also stuck here with no way to order my results other than what was suggested by Steve (array.sort).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below is a "watered-down" version of the two different sets of code that I used for testing:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
//TEST 1: Use existing featureLayer to perform query
var selectQuery&amp;nbsp; = new esri.tasks.Query();
selectQuery.geometry = geometry;
selectQuery.orderByFields = ["MEASURE ASC"];
pointFeatureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW); 


//TEST 2: Use QueryTask to query MapServer Layer
var queryTaskOperation = new esri.tasks.QueryTask("http://myserver:6080/arcgis/rest/services/FeatureServices/TestEditngService/MapServer/0");
query.outFields = ["OBJECTID", "REACHCODE", "REACHRESOLUTION", "MEASURE", "EVENTTYPE"];

var query= new esri.tasks.Query();
query.geometry = geometry;
query.orderByFields = ["MEASURE DESC"];
query.returnGeometry = true;

queryTaskOperation.execute(query, function (featureSet) {
&amp;nbsp; alert("total features = " + featureSet.features.length);
&amp;nbsp; //NOTE: I step through the code and can see what the returned featureSet.features array looks like here!
}, function (e) {
&amp;nbsp; alert("Error during query task");
});
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 12:48:05 GMT</pubDate>
    <dc:creator>DianaBenedict</dc:creator>
    <dc:date>2021-12-11T12:48:05Z</dc:date>
    <item>
      <title>Sorting attribute table</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260243#M24078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to display geographies on a map which have five(5), or any number, highest values of an attribute. Similarly, I would like to display the bottom X number of geographies based on an attribute. For both these queries, I need to sort the attribute table based on the attribute of interest. I am not sure where to begin and how to accomplish this. Can someone please point me to the right source of information for this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Samir&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Feb 2013 18:01:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260243#M24078</guid>
      <dc:creator>SamirGambhir</dc:creator>
      <dc:date>2013-02-04T18:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting attribute table</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260244#M24079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you can get the featureSet of your layer, you could sort the featureSet since it really just is an array:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; var _sort = function(field) { &amp;nbsp;&amp;nbsp;&amp;nbsp; return function(a, b) { &amp;nbsp;&amp;nbsp; var x, y; &amp;nbsp;&amp;nbsp; x = a.attributes[field]; &amp;nbsp;&amp;nbsp; y = b.attributes[field];&amp;nbsp; &amp;nbsp;&amp;nbsp; return (x &amp;lt; y) ? -1 : 1; &amp;nbsp;&amp;nbsp;&amp;nbsp; };&amp;nbsp; };&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theFeatureSet.sort(_sort('Your Field Name'));&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another way of sorting the featureSet would be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; theFeatureSet.sort(function(a,b) { &amp;nbsp; return a.attributes.fieldName - b.attributes.fieldName;&amp;nbsp; });&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Both of my examples would be for a numeric field.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Feb 2013 19:17:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260244#M24079</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2013-02-04T19:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting attribute table</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260245#M24080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you looked at the esri.tasks.query.orderByFields method?&amp;nbsp; Here is the help documentation link&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#Query/groupByFieldsForStatistics"&gt;http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#Query/groupByFieldsForStatistics&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will want to be sure to read the specific information about this method since it requires layers that support advanced queries.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You might also want to look at the StatisticDefinition class (esri.tasks.StatisticDefinition) to see if you can use the statistics type of "count" to return your unique list of values for example. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can use either the esri.tasks.QueryTask or esri.layers.FeatureLayer.queryFeatures to pass in the esri.tasks.query object to perform your query.&amp;nbsp; The results will give you a FeatureSet that you can further manipulate as needed (as indicated above).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure if this is what you need but figured it is worth a try. Good luck&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 14:03:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260245#M24080</guid>
      <dc:creator>DianaBenedict</dc:creator>
      <dc:date>2013-02-05T14:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting attribute table</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260246#M24081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Have you looked at the esri.tasks.query.orderByFields method?&amp;nbsp; Here is the help documentation link&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#Query/groupByFieldsForStatistics" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#Query/groupByFieldsForStatistics&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;You will want to be sure to read the specific information about this method since it requires layers that support advanced queries.&lt;BR /&gt;&lt;BR /&gt;You might also want to look at the StatisticDefinition class (esri.tasks.StatisticDefinition) to see if you can use the statistics type of "count" to return your unique list of values for example. &lt;BR /&gt;&lt;BR /&gt;You can use either the esri.tasks.QueryTask or esri.layers.FeatureLayer.queryFeatures to pass in the esri.tasks.query object to perform your query.&amp;nbsp; The results will give you a FeatureSet that you can further manipulate as needed (as indicated above).&lt;BR /&gt;&lt;BR /&gt;Not sure if this is what you need but figured it is worth a try. Good luck&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Diana and Steve, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried both your options but it did not seem to work. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried query.orderByFeilds, as Diana suggested, as the code below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if (rate == "higher rates") { //retrieved from the user selection using a combobox
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldOrderString = '["' + indv + ' ASC"]'; //'indv' is the indicator selected
&amp;nbsp; } else if (rate == "lower rates") {
&amp;nbsp;&amp;nbsp; fieldOrderString = '["' + indv + ' DESC"]';
&amp;nbsp; }
&amp;nbsp; query.orderByFields = fieldOrderString;
&amp;nbsp; queryTask.execute(query, function(featureSet) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for ( i = 0; i &amp;lt; numg; i++) { //'numg' is the number of features that user would like to be selected
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var features = featureSet.features&lt;I&gt;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp; });&lt;/I&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;and I get an error "Object ["All_CBR ASC"] has no method 'join' " where 'All_CBR' is the user selected indicator&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried Steve's suggestion in the folowing code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;stateFeatureLayer.queryFeatures(query, function (featureSet){ //'stateFeatureLayer' is the feature layer
&amp;nbsp; featureSet.sort(function(a,b) {
&amp;nbsp;&amp;nbsp; return a.attributes.All_CBR - b.attributes.All_CBR;
&amp;nbsp; });
&amp;nbsp; });&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;This gives me a type error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I believe I am not using your suggestions correctly, and I apologize for that. Could you please let me know how to improve on this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Samir&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:48:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260246#M24081</guid>
      <dc:creator>SamirGambhir</dc:creator>
      <dc:date>2021-12-11T12:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting attribute table</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260247#M24082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Samir&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What type of layer are you performing your query on and what version of ArcGIS Server?&amp;nbsp; According to the documentation you have serveral requirements that must be met in order to use orderByFields query param. I have listed them below: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) orderByFields is only supported on dynamic layers and tables where supportsAdvancedQueries is true&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) Requires ArcGIS Server service version 10.1 or greater (As of v2.6)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2013 19:09:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260247#M24082</guid>
      <dc:creator>DianaBenedict</dc:creator>
      <dc:date>2013-02-20T19:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting attribute table</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260248#M24083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Samir&lt;BR /&gt;&lt;BR /&gt;What type of layer are you performing your query on and what version of ArcGIS Server?&amp;nbsp; According to the documentation you have serveral requirements that must be met in order to use orderByFields query param. I have listed them below: &lt;BR /&gt;1) orderByFields is only supported on dynamic layers and tables where supportsAdvancedQueries is true&lt;BR /&gt;2) Requires ArcGIS Server service version 10.1 or greater (As of v2.6)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I apologize, I should have mentioned the version. It is 10.1. I am running orderByFields on a feature layer. I believe that itself rules out the use of this method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Samir&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2013 19:31:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260248#M24083</guid>
      <dc:creator>SamirGambhir</dc:creator>
      <dc:date>2013-02-20T19:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting attribute table</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260249#M24084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Samir&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think what they mean "dynamic layers" as a property of the service.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;NOTE: this is a property of the ArcGIS REST Services Directory for your MapService&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Supports Dynamic Layers: true&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not too sure if this is the correct way for you to follow.&amp;nbsp; I just tried implementing what you are trying to do and had no success. However, in my case, the queries ran correctly with no errors but the featureSet was not "ordered by" the field that I indicated.&amp;nbsp; Sometimes it would actually change my result set based on OBJECTID ASC or DESC order (which I had indicted in the orderByFields param) but it NEVER sorted by the field that I indicated.&amp;nbsp; I am not sure if I was implementing it correctly&amp;nbsp; ... but my results were inconclusive.&amp;nbsp; I tried it with both a featureLayer.selectFeatures and an MapService URL via a QueryTask.execute.&amp;nbsp; No luck.&amp;nbsp; Sorry, I wish I could be more of help but I am also stuck here with no way to order my results other than what was suggested by Steve (array.sort).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below is a "watered-down" version of the two different sets of code that I used for testing:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
//TEST 1: Use existing featureLayer to perform query
var selectQuery&amp;nbsp; = new esri.tasks.Query();
selectQuery.geometry = geometry;
selectQuery.orderByFields = ["MEASURE ASC"];
pointFeatureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW); 


//TEST 2: Use QueryTask to query MapServer Layer
var queryTaskOperation = new esri.tasks.QueryTask("http://myserver:6080/arcgis/rest/services/FeatureServices/TestEditngService/MapServer/0");
query.outFields = ["OBJECTID", "REACHCODE", "REACHRESOLUTION", "MEASURE", "EVENTTYPE"];

var query= new esri.tasks.Query();
query.geometry = geometry;
query.orderByFields = ["MEASURE DESC"];
query.returnGeometry = true;

queryTaskOperation.execute(query, function (featureSet) {
&amp;nbsp; alert("total features = " + featureSet.features.length);
&amp;nbsp; //NOTE: I step through the code and can see what the returned featureSet.features array looks like here!
}, function (e) {
&amp;nbsp; alert("Error during query task");
});
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:48:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260249#M24084</guid>
      <dc:creator>DianaBenedict</dc:creator>
      <dc:date>2021-12-11T12:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting attribute table</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260250#M24085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Samir&lt;BR /&gt;&lt;BR /&gt;I think what they mean "dynamic layers" as a property of the service.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;NOTE: this is a property of the ArcGIS REST Services Directory for your MapService&lt;BR /&gt;Supports Dynamic Layers: true&lt;BR /&gt;&lt;BR /&gt;I am not too sure if this is the correct way for you to follow.&amp;nbsp; I just tried implementing what you are trying to do and had no success. However, in my case, the queries ran correctly with no errors but the featureSet was not "ordered by" the field that I indicated.&amp;nbsp; Sometimes it would actually change my result set based on OBJECTID ASC or DESC order (which I had indicted in the orderByFields param) but it NEVER sorted by the field that I indicated.&amp;nbsp; I am not sure if I was implementing it correctly&amp;nbsp; ... but my results were inconclusive.&amp;nbsp; I tried it with both a featureLayer.selectFeatures and an MapService URL via a QueryTask.execute.&amp;nbsp; No luck.&amp;nbsp; Sorry, I wish I could be more of help but I am also stuck here with no way to order my results other than what was suggested by Steve (array.sort).&lt;BR /&gt;&lt;BR /&gt;Below is a "watered-down" version of the two different sets of code that I used for testing:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
//TEST 1: Use existing featureLayer to perform query
var selectQuery&amp;nbsp; = new esri.tasks.Query();
selectQuery.geometry = geometry;
selectQuery.orderByFields = ["MEASURE ASC"];
pointFeatureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW); 


//TEST 2: Use QueryTask to query MapServer Layer
var queryTaskOperation = new esri.tasks.QueryTask("http://myserver:6080/arcgis/rest/services/FeatureServices/TestEditngService/MapServer/0");
query.outFields = ["OBJECTID", "REACHCODE", "REACHRESOLUTION", "MEASURE", "EVENTTYPE"];

var query= new esri.tasks.Query();
query.geometry = geometry;
query.orderByFields = ["MEASURE DESC"];
query.returnGeometry = true;

queryTaskOperation.execute(query, function (featureSet) {
&amp;nbsp; alert("total features = " + featureSet.features.length);
&amp;nbsp; //NOTE: I step through the code and can see what the returned featureSet.features array looks like here!
}, function (e) {
&amp;nbsp; alert("Error during query task");
});
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve's code actually worked for me. I made minor modifications and the code is below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;myFeatureLayer.queryFeatures(query, function(featureSet) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureSet.features.sort(function(a, b) {
&amp;nbsp;&amp;nbsp; return a.attributes[myField] - b.attributes[myField]; //ascending order
&amp;nbsp; });
});&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Samir&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:48:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sorting-attribute-table/m-p/260250#M24085</guid>
      <dc:creator>SamirGambhir</dc:creator>
      <dc:date>2021-12-11T12:48:07Z</dc:date>
    </item>
  </channel>
</rss>

