user120118
user120118

Reputation: 65

Customize the sorting in datagrid in flex

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 ?

Upvotes: 0

Views: 2363

Answers (2)

cliff.meyers
cliff.meyers

Reputation: 17734

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

Upvotes: 1

Wael Dalloul
Wael Dalloul

Reputation: 23044

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..

Upvotes: 0

Related Questions