[mapguide-users] RE: How to sort a selection set

soudemans soudemans at ruekert-mielke.com
Mon Jan 30 17:25:20 EST 2012

Hmm, hadn't thought about it in that light.  But it seems you are
correct, I am sorting an array of JSON objects


Alright so I tried my hand at this, and to be honest it is a little over
my head.  I found a JavaScript function that I could use to sort the
values in the Array.  It looks like this:


var sort_by = function(field, reverse, primer){

     var key = function (x) {return primer ? primer(x[field]) :

          return function (a,b) {

                var A = key(a), B = key(b);

                return ((A < B) ? -1 : (A > B) ? +1 : 0) *




And the suggested usage would be something like this:
// Provided example: Sort by city, case-insensitive, A-Z 
homes.sort(sort_by('city', false, function(a){return a.toUpperCase()}));


The following is what I basically put together.  Unfortunately I have no
clue what the primer is supposed to do so I went with the previous
example since it didn't matter if the main_ID was lower or upper case.
Alas it isn't working and I am not sure what is wrong or where to go
from here.  


results = results.sort(sort_by('MAIN_ID',false,function(a){return


Any thoughts? 



If you reply to this email, your message will be added to the discussion


To unsubscribe from How to sort a selection set, click here
w0MzQ0MzgzfC0xMzkyMzk3NTUy> .

View this message in context: http://osgeo-org.1560.n6.nabble.com/How-to-sort-a-selection-set-tp4344383p4352080.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20120130/62126119/attachment.html

More information about the mapguide-users mailing list