Select to view content in your preferred language

Sample Flex Viewer - Sort on the Search widget to return records alphabetically

1354
2
05-19-2010 09:17 AM
MegPeterson
Regular Contributor
This seems like a rather easy question, but does anyone know how to return a search alphabetically by a field name?

I have the following fields returned in a search:
PTA_NUMBER,PARKNAME,LOCATION,FIREENTRY,WORKPLAN
but I would like the records to be sorted alphabetically by the ParkName.

I found this post for LiveLayers, but am a little confused how to implement it for the Search Widget (assuming it�??s supposed to go within the function createRecordData?).

http://forums.esri.com/thread.asp?c=158&f=2421&t=285419


var recAC:ArrayCollection = createRecordData(featureSet);
//BJ: sort out the data, 7/2/2009
var dataSortField:SortField = new SortField();
dataSortField.name="title";
var alphabetDataSort:Sort = new Sort();
alphabetDataSort.fields=[dataSortField];
recAC.sort=alphabetDataSort;
recAC.refresh();
//BJ: End

And this post as well:
http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-clas...

but I�??m just not sure how to implement....

Any help would be appreciated. Thanks.
Tags (2)
0 Kudos
2 Replies
DanielAlvarez
New Contributor
you can't use the example from de LiveLayers because you have the field PARKNAME inside a string (
recAC[0].content), which you won't be able to separate and sort by that... I tried to sort it before that but the same problem happened, when you recive the query you get a featureset.features wich is an array but can use Array.sort() cause the field are in a second array called attributes.

I gues the other two options are, 1 try to make a more complex Array.sort(complexNewFunction) so it can look inside the attributes array and compare.

Or try to sort the query before you even send it, i mean on the SerachWidget.xml configuration file, maybe you can specify a SORT BY an the end of the query (dont know much on the gis side).

Hope this help at least on trying a different approach
0 Kudos
DaveKirkley
Occasional Contributor
Works Great!  Thanks Guys:cool:
0 Kudos