1 Reply Latest reply on Apr 7, 2010 11:30 AM by Flex harUI

    sortCompareFunction question

    BosDog Level 1

      how would i specify the datacolumn name that i want to sort based on the one the user clicked? i am able to do this only by strong typing the datafield but i want to be able to just put the sortCompareFunction on every dollar value column I have in the DB and have it know which one the user is trying to sort without hard typing it:

       

      for example:

       

      I have an actionscript function like this:

       

       

      private function price_sortCompareFunc(itemA:Object, itemB:Object):int {

       

      return ObjectUtil.numericCompare(itemA.TOTAL_LP, itemB.TOTAL_LP);

      }

       

      and datagrid with a datacolumn and sortCompareFunction like this:

       

       

      <mx:DataGridColumn

       

      headerText="List Price" sortCompareFunction="{price_sortCompareFunc}" labelFunction="{price_labelFunc}" dataField="TOTAL_LP" width="110" textAlign="right"/>

       

       

       

       

      see how I am specifically calling out TOTAL_LP in the returned variable in the function? how can i have the function dynamically plug this in?

      i've tried adding column:DataGridColumn after the itemB:Object in the function but get the expecting 3 parameters and got 2 error. but notice how the sort compare function never needs to reference the 2 elements anyway... why is that?