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

    Datagrid Sorting

    pvjedder
      I have a datagrid that gets its data from an HTTP service result. On the return of this HTTP Service, I would like to then sort this grid on one of the columns without actually clicking the header to sort by (assume I cannot do the sorting in the HTTP service). Essentially, is there any way to perform a datagrid sort without actually clicking a header?
        • 1. Re: Datagrid Sorting
          chris.huston.t10 Level 3
          If you can convert your HTTP service result to an ArrayCollection or XMLListCollection and use it as your dataProvider for your dataGrid, then you can perform a sort on the collection and do a refresh so that it will sort your dataGrid on whatever column you want.

          Here is a simple example function:

          private function sort_dg():void {
          var dgSort:Sort = new Sort();
          dgSort.fields = [new SortField("YourColumnHere",true)];
          yourArrayCollection.sort = dgSort;
          yourArrayCollection.refresh();
          }

          Vygo
          • 2. Re: Datagrid Sorting
            PhilipKeiter Level 2

            Hello pvjedder,

             

            If it makes it easier for your situation, you can do it directly on the dataProvider property of the DataGrid:

             

            (this assumes the DataGrid's dataProvider was bound to the service result. if not, assign it first)

             

            private function handleHTTPResult(event:Result)

            {

            var sort:Sort = new Sort();

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

            sort.fields = [field];

             

            ListCollectionView(dataGrid.dataProvider).sort = sort;

            ListCollectionView(dataGrid.dataProvider).refresh();

            }

             

            Thanks,

            Philip

             

            Message was edited by: PhilipKeiter