views:

681

answers:

2

I have a column with 4 fields named : a> Main, b> Forward c> Back d> Link, if I use pre-defined sorting of datagrid with the column names which will be alphabetically, then the order is c>Back b>Forward d> Link a> Main. But, I do not want to sort based on the alphabets. I prefer to sort by names of the column fields. i.e. somehow give priority to each individual column field names. Like pre-define my own order.

Is it possible in flex ?

A: 

I have a column with 4 fields named

you mean records not fields, to do what you want I think you should add one more column such as "vote" integer. and increase the value when the user click up and decrease it when the user click down... like what we have here..

Wael Dalloul
+1  A: 

Write a function with the following signature and then specify it as the "sortCompareFunction" property of your DataGridColumn:

mySortCompareFunction(obj1:Object, obj2:Object):int

obj1 — A data element to compare.

obj2 — Another data element to compare with obj1.

The function should return a value based on the comparison of the objects:

  • -1 if obj1 should appear before obj2 in ascending order.
  • 0 if obj1 = obj2.
  • 1 if obj1 should appear after obj2 in ascending order.

Note: The obj1 and obj2 parameters are entire data provider elements and not just the data for the item.

http://livedocs.adobe.com/flex/3/langref/mx/controls/dataGridClasses/DataGridColumn.html#sortCompareFunction

Some sorting examples here:

http://blog.flexexamples.com/2008/04/09/creating-a-custom-sort-on-a-datagrid-control-in-flex/#more-590

cliff.meyers
Can you provide some small code to visualise it more better ? For eg. taking 2 different columns and comparing them. Thanks.
Added a link to some examples at the bottom.
cliff.meyers