3 Replies Latest reply on Mar 15, 2012 10:39 PM by Patel Bharat

    Retrieving column number in the datagrid

    nash99
      Hi ,
      I was trying to retrieve the column number in the datagrid , when we click on the header of the datagrid(on the corresponding column).
      are there any events to retrieve the column number of the column selected .
      I tried using the headerRelease="ClickEvent(event); in the
      <mx:DataGrid id="dg"
      width="100%" height="50" rowHeight="50" editable="true"
      headerRelease="ClickEvent(event);">

      I was able to get the column number using this but
      when the event is called the control is sorting the datagrid column .
      I dont want the datagrid column to be sorted (I tried giving sortable = false , it does'nt help).
      Is there any other way , I could get the data grid column number , when the data grid column header is clicked.

      thanks


        • 1. Re: Retrieving column number in the datagrid
          Murshed1992 Level 1

          Since it is going to sort when you click on the header, you can redirect the sort function:

           

          sortCompareFunction="myFuncName"

          • 2. Re: Retrieving column number in the datagrid
            jfb00 Level 3

            Hi,

            Why do you need the column number?

            What are you trying to do?

            • 3. Re: Retrieving column number in the datagrid
              Patel Bharat Level 2

              Hi

               

              Try below code. On column header click, will get column number / index:

               

               

              <mx:Script>

                  <![CDATA[

                            import mx.events.DataGridEvent;

                 

                      import mx.events.ListEvent;

                      private function itemClickEvent(event:DataGridEvent):void {

                          clickColumn.text=String(event.columnIndex);

                          eventType.text=event.type;

                      }

                  ]]>

                  </mx:Script>

                  <mx:DataGrid id="myGrid" width="350" height="150"

                          headerRelease="itemClickEvent(event)">

                      <mx:ArrayCollection>

                          <mx:Object Artist="Pavement" Price="11.99"

                              Album="Slanted and Enchanted" />

                          <mx:Object Artist="Pavement" Album="Brighten the Corners"

                              Price="11.99" />

                      </mx:ArrayCollection>

                  </mx:DataGrid>

               

               

                  <mx:Form>

                      <mx:FormItem label="Column Index:">

                          <mx:Label id="clickColumn"/>               

                      </mx:FormItem>

                      <mx:FormItem label="Type:">

                          <mx:Label id="eventType"/>             

                      </mx:FormItem>

                  </mx:Form>

               

               

               

              Enjoy RIA ..