arcgis-js-api

Change default Sort order for Arcgis Javascript Feature Table


I would like to have my Feature Table display sorted on the first column when it first appears instead of requiring the user to sort it by clicking on the column header. I have not been able to find a method to do this.


Solution

  • Not sure if this is the best solution, it would be nice to be able to set this in the constructor, but if you call myFeatureTable.grid.set('sort', [{ attribute: ''}]); after the grid fires it's load event, this will sort it before it appears in the UI. For example:

    on(myFeatureTable, "load", function(){
      myFeatureTable.grid.set('sort', [{ attribute: "<attribute used in first column>"}]);
    });
    

    Another method if you have not required dojo/on, you can use the on method of the feature table.

    myFeatureTable.on('load', function () {
      // Sort on the Name attribute
      myFeatureTable.grid.set('sort', [{ attribute: "Name" }]);
    })