Im aware a sort() function exists, just not sure where it should be placed in my code. I have a function that draws routes on the map and i'm getting my results that are in my table from those routes. Do I put sort() after the lines are drawn, before the table is populated? or after the table is populated. Here is my code that populates my table.

myMap.Search = {
    gpGetStats: new esri.tasks.Geoprocessor(gpURL),
    getRouteStats: function () {
        var params = {
            "ZIP_CRID": dojo.byId('resultsLayer').value
        resultsLayer.Search.gpGetStats.execute(params, resultsLayer.Search.handleStats);

    handleStats: function (results, messages) {
        // content.sort();

        var content = "";
        content += '<table>';
        content += '<tr><td> ZIP CRID </td><td> Bus </td><td> Res </td><td> Tot </td><td> &lt;200 </td><td> DS Key </td></tr>';

        dojo.forEach(results[0].value.features, function (crid, i) {
            console.log(crid.attributes.ZIP_CRID + ', ');
            content += '<tr><td>' + crid.attributes.ZIP_CRID;
            content += '</td><td> ' + crid.attributes.BUS_CNT;
            content += '</td><td> ' + crid.attributes.RES_CNT;
            content += '</td><td> ' + crid.attributes.TOT_CNT;
            content += '</td><td> ' + crid.attributes.LT_200_IND;
            content += '</td><td> ' + crid.attributes.DS_KEY + '</td></tr>';
        content += '</table>';

        dojo.byId('details').innerHTML = content;

Also a Dojo Grid would be acceptable

1 Answer 1


Do you have control over the GP service? If so, might be the most efficient place to sort the results as it does not require work for the client and you would not have to worry about hitting the max record limit returned by a GP service. However, it is possible to sort the results in javascript: http://davidwalsh.name/array-sort

Here is an example of using a grid: https://developers.arcgis.com/en/javascript/jssamples/find_map_datagrid.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.