<meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hmm, hadn&#8217;t thought about it in that light.&nbsp; But it seems you are correct, I am sorting an array of JSON objects<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Alright so I tried my hand at this, and to be honest it is a little over my head.&nbsp; I found a JavaScript function that I could use to sort the values in the Array.&nbsp; It looks like this:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:blue'>var</span><span style='font-size:9.5pt;font-family:Consolas'> sort_by = <span style='color:blue'>function</span>(field, reverse, primer){<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp; <span style='color:blue'>var</span> key = <span style='color:blue'>function</span> (x) {<span style='color:blue'>return</span> primer ? primer(x[field]) : x[field]};<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style='color:blue'>return</span> <span style='color:blue'>function</span> (a,b) {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style='color:blue'>var</span> A = key(a), B = key(b);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style='color:blue'>return</span> ((A &lt; B) ? -1 : (A &gt; B) ? +1 : 0) * [-1,1][+!!reverse];<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>};<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>And the suggested usage would be something like this:<br></span><span style='font-size:9.5pt;font-family:Consolas'>// Provided example:</span><span style='font-size:10.0pt;font-family:Consolas;color:gray'> Sort by city, case-insensitive, A-Z</span><span style='font-size:10.0pt;font-family:Consolas;color:black'>&nbsp;<span style='background:#EEEEEE'><br></span>homes.sort(sort_by(</span><span style='font-size:10.0pt;font-family:Consolas;color:maroon'>'city'</span><span style='font-size:10.0pt;font-family:Consolas;color:black'>, </span><span style='font-size:10.0pt;font-family:Consolas;color:darkblue'>false</span><span style='font-size:10.0pt;font-family:Consolas;color:black'>, </span><span style='font-size:10.0pt;font-family:Consolas;color:darkblue'>function</span><span style='font-size:10.0pt;font-family:Consolas;color:black'>(a){</span><span style='font-size:10.0pt;font-family:Consolas;color:darkblue'>return</span><span style='font-size:10.0pt;font-family:Consolas;color:black'> a.toUpperCase()}));&nbsp;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:darkgreen'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The following is what I basically put together.&nbsp; Unfortunately I have no clue what the primer is supposed to do so I went with the previous example since it didn&#8217;t matter if the main_ID was lower or upper case.&nbsp; Alas it isn&#8217;t working and I am not sure what is wrong or where to go from here.&nbsp; <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>results = results.sort(sort_by(<span style='color:maroon'>'MAIN_ID'</span>,<span style='color:blue'>false</span>,<span style='color:blue'>function</span>(a){<span style='color:blue'>return</span> a.toUpperCase()}));<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Any thoughts? <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><div class=MsoNormal align=center style='text-align:center'><hr size=1 width="100%" noshade style='color:#CCCCCC' align=center></div><div><div><p class=MsoNormal><b><span style='font-size:9.0pt;font-family:"Tahoma","sans-serif";color:#444444'>If you reply to this email, your message will be added to the discussion below:<o:p></o:p></span></b></p></div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma","sans-serif";color:#444444'><a href="" target="_top" rel="nofollow" link="external">click here</a>.<br><a href="http://osgeo-org.1560.n6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&amp;id=instant_html%21nabble%3Aemail.naml&amp;base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespace&amp;breadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml" target="_top" rel="nofollow" link="external"><span style='font-size:7.0pt;font-family:"Times New Roman","serif"'>NAML</span></a> <o:p></o:p></span></p></div></div>
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://osgeo-org.1560.n6.nabble.com/How-to-sort-a-selection-set-tp4344383p4352080.html">RE: How to sort a selection set</a><br/>
Sent from the <a href="http://osgeo-org.1560.n6.nabble.com/MapGuide-Users-f4182607.html">MapGuide Users mailing list archive</a> at Nabble.com.<br/>