Facility Control

 View Only
  • 1.  Text-align

    Posted 10-07-2020 10:30

    Hello, 

    I working on struct table that contains hebrew and english, so hebrew is right-to-left written. Here is an example: 

    And i want to set columns with English text to left-aligned, and Hebrew right-aligned. Unfortunately, there is no option text-align per column in table config keys. So, i tried to apply the following to English columns , as I know that DB will parse <html>:

    params.setValue("table.0.englishColumn",0, 'myText <style:text-align:west>' ); 

    But this doesn't work for me.. 

    But, for example other attributes is working:

    params.setValue("table.0.englishColumn",0, 'myText <size:big;fg#FF0000;bg#000000>' ); 

    Is there a way to achieve that?

    Thanks,

    Alex.

     

     



  • 2.  RE: Text-align

    Posted 10-07-2020 13:59

    I can't figure out how to do it with just a regular table.   I tried with HTML styles, wrapping the text with <p style=text-align:right"> and </p>.  That right aligns text, but only within the text itself.   The text appears on the left, but if it has multiple lines (with <br>s), they are aligned right.   So that won't work.

    I can make this work with an API table.    I'll paste an example of an API table below (it's pretty big).   

    With an API table, you can specify what parameter or value is shown in each and every cell (with the getParamOid, or getValueAt functions).    AND you can also specify the style of each and every cell with the getCellStyle function.   So you could do something like the following to specify the alignment of column 2:

    getCellStyle: function(row, col) {
      if (col==2 && params.getValue("language",0) == "English") {
        return "text-align:west";
      }

      if (col==2 && params.getValue("language",0) == "Hebrew") {
        return "text-align:east";
      }

      return "";
    },

     

    Here is the example API table panel:

    <abs contexttype="opengear" gridsize="20" id="_top" keepalive="false">
    <abs height="220" left="40" style="bg#buttonbg;" top="640" width="560">
    <abs left="260" top="40"/>
    <table height="20" left="20" oid="checkbox1" top="20" width="160">
    <tr>
    <label anchor="east" fill="none" insets="0,0,0,5" name="checkbox1" weightx="0.0"/>
    <param anchor="west" expand="true" fill="both" oid="checkbox1" showlabel="false" weightx="1.0" weighty="1.0"/>
    </tr>
    </table>
    <table height="20" left="20" oid="toggle1" top="60" width="160">
    <tr>
    <label anchor="east" fill="none" insets="0,0,0,5" name="toggle1" weightx="0.0"/>
    <param anchor="west" expand="true" fill="both" oid="toggle1" showlabel="false" weightx="1.0" weighty="1.0"/>
    </tr>
    </table>
    <simplegrid cols="1" height="160" left="240" top="40" width="140">
    <param expand="true" oid="array1" showlabel="false"/>
    </simplegrid>
    <label height="20" left="240" name="array1" style="txt-align:west" top="20" width="120"/>
    </abs>
    <meta>
    <params>
    <param access="1" constrainttype="INT_NULL" name="Table" oid="params.table" precision="0" type="INT16" value="4" widget="script-table"/>
    <param access="1" constrainttype="INT_CHOICE" name="checkbox1" oid="checkbox1" precision="0" type="INT16" value="1" widget="checkbox">
    <constraint key="0">Off</constraint>
    <constraint key="1">On</constraint>
    </param>
    <param access="1" constrainttype="INT_CHOICE" name="toggle1" oid="toggle1" precision="0" type="INT16" value="2" widget="combo">
    <constraint key="0">North</constraint>
    <constraint key="1">South</constraint>
    <constraint key="2">East</constraint>
    <constraint key="3">West</constraint>
    </param>
    <param access="1" maxlength="0" name="array1" oid="array1" precision="0" type="STRING_ARRAY" widget="default">
    <value>horse</value>
    <value>dog</value>
    <value>platypus</value>
    <value>cat</value>
    <value>wombat</value>
    <value>sheep</value>
    </param>
    </params>
    </meta>
    <param expand="true" height="320" left="40" oid="params.table" showlabel="false" top="160" width="560">
    <config key="w.model">var model = {


    getRowCount: function()
    {
    return 5;
    },

    getColumnCount: function()
    {
    return 4;
    },

    getRowHeight: function(row)
    {
    // Make the rows get bigger and bigger.
    return 20 + row *10;

    },

    getColumnName: function(col)
    {
    if (col==0) {
    return "FIRST"
    }
    if (col==1) {
    return "SECOND"
    }
    return "COL " + col;
    },


    getHeaderWidth: function(col)
    {
    switch (col) {
    case 0: {return 60}
    case 1: {return 120}
    case 2: {return 60}
    case 3: {return 200}
    case 4: {return 75}
    }
    },


    getValueAt: function(row,col) {
    if (col == 0) {
    switch (row) {
    case 0: {return "Apple"}
    case 1: {return "Banana"}
    case 2: {return "Coconut"}
    case 3: {return "Date"}
    case 4: {return "Eldberry"}
    }
    }
    if (row == 1 &amp;&amp; col == 1) {
    return null;
    }
    if (row == 2 &amp;&amp; col == 2) {
    return null;
    }
    if (col == 3) {
    return null;
    }
    return "Row: " + row + " Col: " + col;
    },

    getParamOid: function(row, col)
    {
    if (row == 1 &amp;&amp; col == 1) {
    return "checkbox1"
    }
    if (row == 2 &amp;&amp; col == 2) {
    return "toggle1"
    }
    if (col == 3) {
    return "array1";
    }
    return null;
    },

    getCellStyle: function(row, col) {
    if (col==2 &amp;&amp; row==4) {
    return "bg#2222aa;fg#888888;size:Bigger;";
    }
    if (col==1) {
    return "bg#aa2222;fg#dddddd";
    }
    if (row % 2 == 0) {
    return "bg#888888; fg#ffffff";
    }

    },


    getParamIndex: function(row, col)
    {
    if (col == 3) {
    return row;
    }
    return 0;
    },

    selectionChanged: function(rows, cols)
    {
    ogscript.rename("message", "user selected from " + rows[0] + " , " + cols[0] + " to " + rows[rows.length-1] + " , " + cols[cols.length-1]);
    },

    headerClicked: function(col)
    {
    ogscript.rename("message", 'Header Clicked: ' + col);
    },

    isCellEditable: function(row, col)
    {
    if (col == 3) {
    return false;
    }
    return true;
    },

    isSortable: function()
    {
    return true;
    },

    }

    model</config>
    </param>
    <label height="53" left="40" name="API Table" style="txt-align:west;size:Bigger;" top="18" width="605"/>
    <label height="40" left="40" name="API Tables allow you to create tables that have custom data or parameters in each and every cell. You can also style each cell individually" style="txt-align:west;" top="60" width="1040"/>
    <table height="600" left="660" top="200" width="620">
    <tr>
    <label colspan="1" fill="both" name="getRowCount" rowspan="1" style="txt-align:west" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="Returns the number of rows in the table." rowspan="1" style="txt-align:west" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="getColumnCount" rowspan="1" style="txt-align:west" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="Returns the number of columns in the table" rowspan="1" style="txt-align:west" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="getRowHeight" rowspan="1" style="txt-align:west" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="&lt;html&gt;Input: row&lt;br/&gt;Returns the height of the input row.&lt;/html&gt;" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="getHeaderWidth" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" id="" name="&lt;html&gt;Input: col&lt;br/&gt;Returns the width of the specified col.&lt;/html&gt;" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="getColumnName" rowspan="1" style="txt-align:west" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="&lt;html&gt;Input: col&lt;br/&gt;Returns the name of the input column.&lt;/html&gt;" rowspan="1" style="txt-align:west" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="getValueAt" rowspan="1" style="txt-align:west" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="&lt;html&gt;Input: row, col&lt;br/&gt;Returns the value to display in the cell at row,col&lt;br&gt;Return null if you want to use a param instead.&lt;/html&gt;" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="getParamOid" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="&lt;html&gt;Input: row, col&lt;br/&gt;Returns which parameter to show in cell row,col. &lt;br/&gt;Return null if you don't want to show a parameter, but use a value instead.&lt;/html&gt;" rowspan="1" style="txt-align:west" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="getCellStyle" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="&lt;html&gt;Input: row, col&lt;br/&gt;Returns the style string to use at cell row,col.&lt;/html&gt;" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="selectionChanged" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="&lt;html&gt;Input: rows, cols&lt;br/&gt;When the user selects a part of the table, this function is called. &lt;br/&gt;It contains an array for the selected rows, and one for the selected columns.&lt;/html&gt;" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="headerClicked" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="&lt;html&gt;Input: col&lt;br/&gt;This function is called when a table header is clicked. &lt;br&gt;The col input specifies which header was clicked.&lt;/html&gt;" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="getParamIndex" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="&lt;html&gt;Input: row, col&lt;br/&gt;If the parameter returned by &quot;getParamOid&quot; is an array, &lt;br/&gt;you can specify which index of the array to use with this function.&lt;/html&gt;" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="isCellEditable" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="&lt;html&gt;input: row, col&lt;br/&gt;returns true if the cell at row,col is editable, false otherwise.&lt;/html&gt;" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    </tr>
    <tr>
    <label colspan="1" fill="both" name="isSortable" rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    <label colspan="1" fill="both" name="returns true if the user can click on the headers to sort the columns, false otherwise." rowspan="1" style="txt-align:west;" weightx="1.0" weighty="1.0"/>
    </tr>
    </table>
    <label height="40" id="message" left="40" name="Click on the table or headers to change this message" style="txt-align:west;" top="480" width="380"/>
    <label height="20" left="40" name="To create one, create an INT16 parameter, and set its widget hint to &quot;script-table&quot;. Then add w.model config option." style="txt-align:west;" top="100" width="920"/>
    <label height="20" left="660" name="The w.model is an object that contains functions that control the content and look of the table." style="txt-align:west" top="140" width="560"/>
    <label height="20" left="660" name="It can have the following functions:" style="txt-align:west;" top="160" width="560"/>
    <label height="40" left="40" name="The following parameters are embedded in the table:" style="txt-align:west;size:Big;" top="580" width="560"/>


    </abs>


    #DashBoard


  • 3.  RE: Text-align

    Posted 10-07-2020 14:18

    Hi Ben,

    I have only one Hebrew column  - and this is my constant. getCellStyle() is unnecessary, since I don't need to find out which cell is Hebrew and which is not. I just need to hard fixed east-aligned column 2 (in west-aligned table).

    Is that make it easier? Or still, no way to escape API table (which seems very complicated to me, on first look).

    Thanks for help!


    #DashBoard


  • 4.  RE: Text-align

    Posted 10-07-2020 15:00

    That unfortunately does not make it easier.   

    API tables don't have to be too complicated.   I just made a panel where I took an existing structured param, and implemented the minimal functions needed to make it into an API table (with one column that can go from left-align to right-align).

    The code for the panel is at the end of this post.

    You only really need to:

    1. add a parameter for the api table (mine is called params.table).

    2. drop that parameter in your panel, with a model, like this:

     

    As you can see, the whole model fits on one page.   You only really need the following fuctions:

    1. getRowCount - returns the number of elements in your structured parameter

    2. getColumnCount - returns the number of suboids in your structured parameter.

    3. getColumnName - returns the name of each suboid.

    4. getParamOID - returns which parameter to show in which column.

    5. getCellStyle - for column 2, if the language is english, return left align, otherwise return right align.

    That should be all you need.   Just change "players" to the name of your structured parameter, and the column (fname, lname, jersey, etc) to your columns.

     

    Here is the panel.   If you switch from English to Hebrew, you need to hover over the table for the effect to be shown.   Although we could force a refresh of the panel if that parameter changes.

     

     

     

    <abs contexttype="opengear" gridsize="20" id="_top" keepalive="false">
    <meta>
    <params>
    <param access="1" constrainttype="INT_NULL" name="Table" oid="params.table" precision="0" type="INT16" value="5" widget="script-table"/>
    <param access="1" constrainttype="STRUCT" name="player_template" oid="player_template" type="STRUCT" widget="table">
    <value>
    <subparam access="1" maxlength="0" name="First Name" suboid="fname" type="STRING" value="First" widget="default"/>
    <subparam access="1" maxlength="0" name="Last Name" suboid="lname" type="STRING" value="Last" widget="default"/>
    <subparam access="1" constrainttype="INT_NULL" name="Jersey" precision="0" suboid="jersey" type="INT16" value="0" widget="default"/>
    <subparam access="1" maxlength="0" name="Team" suboid="team" type="STRING" value="Team" widget="default"/>
    <subparam access="1" constrainttype="FLOAT_NULL" name="Height" precision="3" suboid="height" type="FLOAT32" value="2.0" widget="default"/>
    </value>
    </param>
    <param access="1" constrainttype="STRUCT" name="player_template" oid="players" templateoid="player_template" type="STRUCT_ARRAY" widget="table">
    <value>
    <subparam suboid="fname" value="Charles"/>
    <subparam suboid="lname" value="Barkley"/>
    <subparam suboid="jersey" value="34"/>
    <subparam suboid="team" value="Suns"/>
    <subparam suboid="height" value="1.98"/>
    </value>
    <value>
    <subparam suboid="fname" value="Kevin"/>
    <subparam suboid="lname" value="Durant"/>
    <subparam suboid="jersey" value="35"/>
    <subparam suboid="team" value="Warriors"/>
    <subparam suboid="height" value="2.08"/>
    </value>
    <value>
    <subparam suboid="fname" value="Scottie"/>
    <subparam suboid="lname" value="Pippen"/>
    <subparam suboid="jersey" value="33"/>
    <subparam suboid="team" value="Bulls"/>
    <subparam suboid="height" value="2.03"/>
    </value>
    <value>
    <subparam suboid="fname" value="Julius"/>
    <subparam suboid="lname" value="Erving"/>
    <subparam suboid="jersey" value="6"/>
    <subparam suboid="team" value="76ers"/>
    <subparam suboid="height" value="2.01"/>
    </value>
    <value>
    <subparam suboid="fname" value="Magic"/>
    <subparam suboid="lname" value="Johnson"/>
    <subparam suboid="jersey" value="32"/>
    <subparam suboid="team" value="Lakers"/>
    <subparam suboid="height" value="2.06"/>
    </value>
    <value>
    <subparam suboid="fname" value="LeBron"/>
    <subparam suboid="lname" value="James"/>
    <subparam suboid="jersey" value="23"/>
    <subparam suboid="team" value="Lakers"/>
    <subparam suboid="height" value="2.06"/>
    </value>
    <value>
    <subparam suboid="fname" value="Michael"/>
    <subparam suboid="lname" value="Jordan"/>
    <subparam suboid="jersey" value="23"/>
    <subparam suboid="team" value="Bulls"/>
    <subparam suboid="height" value="1.98"/>
    </value>
    </param>
    <param access="1" constrainttype="STRING_CHOICE" maxlength="0" name="language" oid="language" type="STRING" value="hebrew" widget="radio-toggle">
    <constraint>english</constraint>
    <constraint>hebrew</constraint>
    </param>
    </params>
    </meta>
    <param expand="true" height="180" left="660" oid="players" showlabel="false" top="180" width="340"/>
    <label height="60" left="60" name="Structured Parameter Array" style="txt-align:west;size:Bigger;" top="20" width="560"/>
    <label height="20" left="60" name="Structured parameters can be put into an array, essentially creating a table of data." style="txt-align:west;" top="80" width="760"/>
    <param expand="true" height="180" left="60" oid="params.table" showlabel="false" top="180" width="380">
    <config key="w.model">var model = {


    getRowCount: function()
    {
    var p = params.getParam("players",0);
    return p.getElementCount();
    },

    getColumnCount: function()
    {
    return 5;
    },

    getColumnName: function(col)
    {

    switch (col) {
    case 0: {return "First" }
    case 1: {return "Last"}
    case 2: {return "Jersey" }
    case 3: {return "Team"}
    case 4: {return "Height" }

    }
    return "";
    },

    getParamOid: function(row, col)
    {

    switch (col) {
    case 0: {return "players." + row + ".fname" }
    case 1: {return "players." + row + ".lname"}
    case 2: {return "players." + row + ".jersey" }
    case 3: {return "players." + row + ".team"}
    case 4: {return "players." + row + ".height" }
    }
    },

    getCellStyle: function(row, col) {
    if (col==1) {
    if (params.getValue("language",0) == "english") {
    return "txt-align:west;";
    } else {
    return "txt-align:east;";
    }
    }


    }

    }

    model</config>
    </param>
    <label height="20" left="60" name="API Table" style="txt-align:west" top="140" width="180"/>
    <label height="20" left="660" name="Structured Table" style="txt-align:west" top="140" width="200"/>
    <param expand="true" height="60" left="80" oid="language" showlabel="false" top="560" width="300"/>
    <label height="40" left="700" style="txt-align:east;" top="540" width="160"/>
    </abs>


    #DashBoard


  • 5.  RE: Text-align

    Posted 10-07-2020 15:09

    Ok, Ben I will check it! 
    Thank you very much for that.

    Alex.


    #DashBoard