4 Replies Latest reply on Jun 12, 2007 12:36 PM by schjlatah

    Sorting the order of columns in datagrid

    FlexTutor
      Hi, is there anyway to sort the order columns of a datagrid?

      I have this xml file
      <root>
      <node1 order="1" />
      <node2 order="2" />
      </root>

      I would like to be able to sort columns y retrieving the order attribute of the node.

      Is this possible?

      Many thanks for help!
        • 1. Re: Sorting the order of columns in datagrid
          jlingwai Level 1
          I think you best bet is to put your xml into an arraycollection and then you can sort by the order field. Then use the arraycollection as your datagrid provider.

          -JoSh
          • 2. Re: Sorting the order of columns in datagrid
            FlexTutor Level 1
            Ok, I have done that, but what I am trying to do is to sort the columns order, not the rows. Flex by default sort them alphabetically.

            Many thanks for your answer, anyway!
            • 3. Re: Sorting the order of columns in datagrid
              FlexTutor Level 1
              Another question, maybe you can help me! If I put the xml into an arrayCollection, how do I retrieve the name of the node? I am able to retrieve the content and attributes, but I would like to know if it is possible to retrieve the name of the node.

              For istance:

              <root>
              <book_name>Test</book_name>
              </root>

              how do i retrieve the part "book_name"?

              Many thanks again!
              • 4. Sorting the order of columns in datagrid
                schjlatah
                You can try explicitly defining your DataGridColumns, like this:

                <mx:DataGrid dataProvider="{yourArrayOfObjects}">
                <mx:columns>
                <mx:DataGridColumn headerText="Book Name" dataField="book_name"/>
                <mx:DataGridColumn headerText="Order" dataField="order"/>
                <mx:DataGridColumn headerText="Other Field" dataField="other"/>
                </mx:columns>
                </mx:DataGrid>

                That should give you the control to order your columns however you want to, and also, to only include what columns you want included.
                If that doesn't work, then I may not be understanding your problem correctly.