Facility Control

 View Only
  • 1.  dashboard soarting

    Posted 12-22-2023 15:01

    hello expert 

    iam trying to built point table for football match,  By sorting parametric table it do not reflect in array value in OID. which is useless to datalinq that paremeter in xpression. 

    so 1st i want to sort it by point and then by goal difference and goal for etc. 

    what is the best way to sove this problem.

    here is the code

    <abs contexttype="opengear" id="_top" objectid="Football_Point_Table.xml">
       
    <param expand="true" height="394" left="29" oddstyle="f:bg-align:center;f:bg#listbg;" oid="ptable" showlabel="false" style="font:bold;" top="38" width="1162">
          <config key="w.sortable">true</config>
          <config key="w.rowheight">40</config>
          <config key="w.cellediting">true</config>
          <config key="w.reorder">true</config>
          <config key="w.localselection">true</config>
          <config key="w.columnlock">true</config>
       </param>
       <button buttontype="push" height="107" left="1277" name="REORDER" style="font:bold;size:Big;" top="81" width="319"/>
    </abs>
     



    ------------------------------
    Sunil Blank
    Freelancer Graphics Designer
    Freelancer
    Kathmandu Nepal
    ------------------------------


  • 2.  RE: dashboard soarting

    Ross Staff
    Posted 03-13-2024 14:49

    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 &lt; a.length-1; i++) {
                
                if (col == 0)
                {
                   if(a[i].number &gt; 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 &gt; 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 &lt; 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 &lt; params.getElementCount('DATA.NUMBER'); ++i)
       {
          params.setValue('DATA.NUMBER', i, "");
          params.setValue('DATA.NAME', i, "");
       }
       
       //re-issue data into params
       for(i = 0; i &lt; 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
    ------------------------------