Hi Sunil
For a persistent sort that actually writes the data back to the parameter in the new order, you will need to do the sorting manually and write it back via ogScript. We do have an example panel that does this:
<abs contexttype="opengear">
<api>function bubbleSort(a, col, reverse)
{
var swapped;
do {
swapped = false;
for (var i=0; i < a.length-1; i++) {
if (col == 0)
{
if(a[i].number > a[i+1].number)
{
var temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
swapped = true;
}
}
if (col == 1)
{
if(a[i].name > a[i+1].name)
{
var temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
swapped = true;
}
}
}
} while (swapped);
if(reverse) a.reverse();
}
function sortData(col, reverse)
{
var data = [];
//gather data into a struct
for(i = 0; i < params.getElementCount('DATA.NUMBER'); ++i)
{
var numValue = params.getValue('DATA.NUMBER', i);
if(numValue)
{
var item = { name: params.getValue('DATA.NAME', i), number: parseInt(numValue) };
data.push(item);
}
}
//do sort - keep in mind this is a bubble sort, not ideal for large sets of data (keep it small else it will slow down)
bubbleSort(data, col, reverse);
//wipe entire table
for(i = 0; i < params.getElementCount('DATA.NUMBER'); ++i)
{
params.setValue('DATA.NUMBER', i, "");
params.setValue('DATA.NAME', i, "");
}
//re-issue data into params
for(i = 0; i < data.length; ++i)
{
if(data[i].number)
{
params.setValue('DATA.NUMBER', i, data[i].number);
params.setValue('DATA.NAME', i, data[i].name);
}
}
}</api>
<meta>
<params>
<param access="1" maxlength="0" name="NAME" oid="DATA.NAME" precision="0" type="STRING_ARRAY" widget="default">
<value>abel</value>
<value>andre</value>
<value>andrew</value>
<value>joe</value>
<value>larry</value>
<value>steve</value>
<value>steven</value>
<value>strongbad</value>
<value>zack</value>
<value>zeus</value>
</param>
<param access="1" maxlength="0" name="#" oid="DATA.NUMBER" precision="0" type="STRING_ARRAY" widget="default">
<value>1.0</value>
<value>9.0</value>
<value>2.0</value>
<value>3.0</value>
<value>5.0</value>
<value>4.0</value>
<value>10.0</value>
<value>8.0</value>
<value>6.0</value>
<value>7.0</value>
</param>
<param access="1" constrainttype="STRING_CHOICE" name="ROSTER.HOME.TABLE" oid="ROSTER.HOME.TABLE" precision="0" type="INT16" value="9" widget="table">
<constraint>DATA.NUMBER</constraint>
<constraint>DATA.NAME</constraint>
</param>
</params>
<lookup/>
</meta>
<param fill="both" height="400" left="20" oid="ROSTER.HOME.TABLE" pheight="400" pwidth="400" rowspan="1" showlabel="false" top="20" width="300"/>
<table height="400" left="310" top="20" width="300">
<tr>
<button buttontype="push" colspan="1" fill="both" name="# DESC" rowspan="1" weightx="1.0" weighty="1.0">
<task tasktype="ogscript">sortData(0,true);</task>
</button>
</tr>
<tr>
<button buttontype="push" colspan="1" fill="both" name="# ASC" rowspan="1" weightx="1.0" weighty="1.0">
<task tasktype="ogscript">sortData(0,false);</task>
</button>
</tr>
<tr>
<button buttontype="push" colspan="1" fill="both" name="Name DESC" rowspan="1" weightx="1.0" weighty="1.0">
<task tasktype="ogscript">sortData(1,true);</task>
</button>
</tr>
<tr>
<button buttontype="push" colspan="1" fill="both" name="Name ASC" rowspan="1" weightx="1.0" weighty="1.0">
<task tasktype="ogscript">sortData(1,false);</task>
</button>
</tr>
</table>
</abs>
The key here is the "sortData" function in the <api/> tag. You can also use getAllValues() and setAllValues to get the existing values as an array and to write the entire array all at once - that's just slightly different from the way the author chose to implement this example.
------------------------------
James Peltzer
Ross Video
------------------------------