Skip to main content
June 24, 2014
Answered

SortItemsOn method (sort data by more fields)

  • June 24, 2014
  • 1 reply
  • 293 views

Hello,

I have a datagrid control that i want to be sorted by two fields instead one. (it works fine with one filed though)

I am using the method SortItemsOn() which according the documentation, Sorts the elements of the current data provider by one or more of its fields.

However if i add two fields i get some weird result. e.g.

datagrid.sortItemsOn("Field1 Field2", Array.NUMERIC);

The Field1 is of date data type and the Field2 is textual field so maybe that's why it does not give the expected result.

Thank you so much

This topic has been closed for replies.
Correct answer kglad

I see. Ok could you please show me or give me a link where i can see an example of multiple fields sorter? Would be greatly appreciated. Thx


i don't know of any for flash.  there are several for flex.

but for flash, just make your own using a custom sort. eg,

function sortGridF():void{

    var dp:DataProvider = datagrid.dataProvider;

    dp.sortOn(["Field1, Field2"], Array.NUMERIC);

}

p.s. please mark correct/helpful responses.

1 reply

kglad
Community Expert
Community Expert
June 24, 2014

that method only accepts one field.  to sort on two fields you'll need to create your own sorter.

June 24, 2014

Hmm then why the documentation says that it "Sorts the elements of the current data provider by one or more of its fields"

SelectableList - Adobe ActionScript® 3 (AS3 Flash) API Reference

kglad
Community Expert
Community Expert
June 24, 2014

couldn't tell you that but it only accepts a string in the first parameter and there's no way to indicate multiple columns with one string.