I need to sort an array, a sub category array actually. I was going to use this: http://docs.miva.com/api-functions/QuickSortArray
so I made a test on here http://snippets.miva.com/id/1454003881/1 with my code I'll post below.
I'm not quite there yet. I added the colorSort to take account for uppercase and lowercase getting sorted differently. I can't actually choose the 2nd parameter successfully yet on QuickSortArray.
Does anyone have any success using QuickSortArray where you tell it what to sort by? Or should I use another function instead?
Colin
My code to paste into the snippet:
Colin
so I made a test on here http://snippets.miva.com/id/1454003881/1 with my code I'll post below.
I'm not quite there yet. I added the colorSort to take account for uppercase and lowercase getting sorted differently. I can't actually choose the 2nd parameter successfully yet on QuickSortArray.
Does anyone have any success using QuickSortArray where you tell it what to sort by? Or should I use another function instead?
Colin
My code to paste into the snippet:
Code:
<mvt:assign name="l.settings:list[1]:name" value="'apples'" />
<mvt:assign name="l.settings:list[1]:kind" value="'mac'" />
<mvt:assign name="l.settings:list[1]:color" value="'a'" />
<mvt:assign name="l.settings:list[2]:name" value="'bananas'" />
<mvt:assign name="l.settings:list[2]:kind" value="'South American'" />
<mvt:assign name="l.settings:list[2]:color" value="'C'" /><mvt:assign name="l.settings:list[3]" value="'Carrots'" />
<mvt:assign name="l.settings:list[3]:name" value="'orange'" />
<mvt:assign name="l.settings:list[3]:kind" value="'Florida'" />
<mvt:assign name="l.settings:list[3]:color" value="'b'" />
<mvt:assign name="l.settings:list[4]:name" value="'orange'" />
<mvt:assign name="l.settings:list[4]:kind" value="'Michigan'" />
<mvt:assign name="l.settings:list[4]:color" value="'d'" />
<h2>Before</h2>
<mvt:foreach iterator="item" array="list">
name: &mvt:item:name;<br>
kind: &mvt:item:kind;<br>
color: &mvt:item:color;<br>
colorSort: &mvt:item:colorSort;
<hr/>
</mvt:foreach>
<h2>Add a key to sort as upper</h2>
<mvt:foreach iterator="item" array="list">
<mvt:assign name="l.settings:item:colorSort" value="toupper(l.settings:item:color)" />
name: &mvt:item:name;<br>
kind: &mvt:item:kind;<br>
color: &mvt:item:color;<br>
colorSort: &mvt:item:colorSort;
<hr/>
</mvt:foreach>
<mvt:do file="g.module_library_utilities" name="l.success" value="QuickSortArray(l.settings:list, colorSort, 1)" />
<h2>Do the sort and see: After</h2>
<mvt:foreach iterator="item" array="list">
name: &mvt:item:name;<br>
kind: &mvt:item:kind;<br>
color: &mvt:item:color;<br>
colorSort: &mvt:item:colorSort;
<hr/>
</mvt:foreach>
Colin
Comment