1 Reply Latest reply on Dec 7, 2009 7:46 PM by PhilipKeiter

    Displaying sort Arrow in DataGrid

    gumnam Level 1
      Hi All ,
      I have this datagrid with paging functionality. (The sorting and paging functionality is served from our own server.)
      My Datagrid has sortableColumns=true, and I am using event.preventDefault() to disable automatic sorting from the DataGrid.

      When a user clicks on the headerRelease, the columnName is being sent to the server to sort the data and return the sorted results. When the result arrives back from the server it's already sorted and is displayed in the grid fine. However, there is no visual indication of the sort direction (ie. I don't see the sort arrow displayed on the header of the column that was clicked).

      I read at this link http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDo cs_Parts&file=00000598.html, that the easiest way to do custom sorting is to provide an instance of Sort class to the dataProvider's sort field and then calling the refresh method on the dataProvider.

      However, since my data has already been sorted , and as it is complex data, I do not want to do client-side sorting (as a) it could end up in data being sorted again unnecessarily and b) could mess up the already sorted data.

      Does anybody know an easier way of how to display sort Arrow in this situation?
        • 1. Re: Displaying sort Arrow in DataGrid
          PhilipKeiter Level 2

          Hello qumnam,


          When you set the sort programmatically, the DataGrid trusts that you did the refresh and just updates the header icons. So, all you have to do is set a sort on the dataProvider and not call refresh after. Then call invalidateDisplayList on the DataGrid so it redraws the headers to match.


          var sort:Sort = new Sort();

          var field:SortField = new SortField("fieldName");

          sort.fields = [field];


          ListCollectionView(dataGrid.dataProvider).sort = sort;

          // Don't process the sort!

          // ListCollectionView(dataGrid.dataProvider).refresh();