2 Replies Latest reply on Dec 7, 2009 8:23 PM by PhilipKeiter

    Datagrid: sort column get & set ??

    Alexander McLeod
      It appears the sort API interfaces for the DataGrid were altered between Flex 2 and 3. Prior to Flex3 there was a property of a DataGrid (sortIndex) which provided the ability to determine which column was the sort column. This property was removed in Flex 3's DataGrid. Perhaps this was removed because a single value is insufficient when multicolumn sorting is in use, however the simplest use case involving the base component seems to allow the user to select one column for sorting by simply clicking on the column header. Best I can tell I can no longer determine (without listening for column header clicks) which column is the sort column.

      Also while I've seen mention of the means to set the sort column by simulating a click on the column header (or 2 clicks to get the sort direction correct) it doesn't seem that this functionality is available either. While pre-sorting the dataset itself is an option that alone does not provide the functionality of indicating the sort column / direction via the column header sort indicators (up/down arrows on the sort column).

      DataGridColumn has a boolean attribute sortDescending via which one can determine if a column is sorting descending or ascending but nothing alone that I can see indicates that a given column is in fact sorting at all.

      Presumably in flex2 for single column sorting one could determine which column was selected and what order the sort was with the DataGrid's sortIndex property and the DataGridColumn's sortDescending property but with the above noted changes and issues I'm not sure how to do this in Flex3.

      Am I missing something here?

      Comments appreciated!

        • 1. Datagrid: sort column get & set ??
          I don't know what was in Flex 2. But I came across this problem in Flex 3 as well. I wanted the data grid to sort by the first column by default.
          After a while I solved it in a dirty way. I just dispatched an event on the datagrid object that indicates that the first column header was clicked. This solved the problem :)
          You can extend the datagrid class to enable nice interface that will do this and all the other features you miss.
          I also hope that this features will be added back to the final release of Flex 3.
          • 2. Re: Datagrid: sort column get & set ??
            PhilipKeiter Level 2



            In Flex 3 sorting is controlled by the collections rather than the controls. This provides greater flexibility overall despite making it hard to adjust to. To get or set a sort on the DataGrid in Flex 3, use the sort property of its dataProvider:




            You can both read and write to the sort property. When you write to it, you have to call refresh() after for it to apply. Refer to the documentation on the ListCollectionView class for how to properly get and set its sort property.