Facility Control

 View Only
  • 1.  Dynamic table generation

    Posted 02-23-2019 04:05
    Is it possible to dynamically generate a table? I've got an XML file I'm parsing and I'd like to just use the data input to generate a table instead of having to pre-define a table that I then fill. I looked through the documentation and I don't see any way to modify a table (or create one from scratch) using ogscript code.

    Thanks!


  • 2.  RE: Dynamic table generation

    Posted 02-25-2019 15:28

    Hi @Lanthade
    There are several ways to achieve this. I have attached an example XML/CustomPanel that will populate 2 columns in a table with the data from an XML file. The trick to updating the basic array-per-column tables is to use params.setAllValues to replace all of the data in the parameter.

    <abs contexttype="opengear" style="">
    <meta>
    <params>
    <param access="1" maxlength="0" name="Column 1" oid="cols.1" precision="0" stateless="true" type="STRING_ARRAY" widget="label">
    <value>
    </value>
    </param>
    <param access="1" constrainttype="INT_NULL" name="Column 0" oid="cols.0" precision="0" stateless="true" type="INT16_ARRAY" value="0" widget="default"/>
    <param access="1" constrainttype="STRING_CHOICE" name="table" oid="table" precision="0" type="INT16" value="-1" widget="table">
    <constraint>cols.0</constraint>
    <constraint>cols.1</constraint>
    </param>
    </params>
    </meta>
    <param bottom="5" expand="true" left="6" oid="table" right="8" showlabel="false" top="104"/>
    <button buttontype="push" height="84" left="5" name="Read" top="7" width="186">
    <task tasktype="ogscript">var xmlDocument = ogscript.parseXML('data.xml'); //Parse the XML
    var nodeList = xmlDocument.getElementsByTagName("team"); //Get the tags we want to include in the constraint

    var colData0 = []; //Placeholder for the new constraint data
    var colData1 = []; //Placeholder for the new constraint data

    for (var i = 0; i &lt; nodeList.getLength(); i++) //Loop through each tag we found
    {
    var node = nodeList.item(i); //Get the node
    colData0.push(parseInt(node.getAttribute("ID")));
    colData1.push(node.getAttribute("name"));
    }


    params.setAllValues('cols.0', colData0);
    params.setAllValues('cols.1', colData1);</task>
    </button>
    </abs>

     

    Table from XML.zip

    James


    #DashBoard


  • 3.  RE: Dynamic table generation

    Posted 02-26-2019 04:19
    Thanks @jamespeltzer that's working well for me.

    Couple additional questions:

    How can I set row/column size?
    How can I set overall table height/width? I've tried the ogscript.setSize("table",500,500) command and it doesn't do anything.
    How do I put a table into a cell?

    I've got some more questions but answers to the above questions will probably lead me to the additional answers I'm looking for.

    Thanks!


    #DashBoard


  • 4.  RE: Dynamic table generation

    Posted 02-26-2019 14:29
    When you are in the editor for the table parameter, you will see a table of "Config Options". If you click on the question mark to the right of the table, you will see a very large list of configurable properties. The one for the widths of the columns is w.colwidth.[column index].

    In the example I gave, setSize will not do anything since the table parameter hasn't been given an ID. You should generally not be setting the size of an OGLML element this way - the size would typically be fixed, set to scale, or otherwise grow/shrink based on what type of container it is inside of. I'm not sure what you mean where you ask about putting a 'table into a cell'.

    Hope this gets you started.

    James
    #DashBoard


  • 5.  RE: Dynamic table generation

    Posted 02-27-2019 15:33

    @jamespeltzer Thanks for working with me on this. I guess what I'm really after is being able to create visible UI elements from ogscript.

    Lets say I've got the following in my panel:

    <param expand="true" height="40" left="60" oid="temp" top="300" widget="1" width="200"/>

     

    How do I create that from a script section? I've tried the following without success from inside a button task:

    var paramObject ={
    "expand": "true",
    "height": "40",
    "left": "60",
    "oid": "temp",
    "top": "400",
    "width": "200"
    };

    var newParam = params.createParam(paramObject);

    My end goal is to build a panel for monitoring a routing system based on a user generated XML file. This way the user can more easily modify the panel without having to know the ins-and-outs of the script and the risk of breaking the panel by trying to add something new to it. To pull this off I at minimum need to generate standard UI elements dynamically (like the one referenced above) as well as the paramaters backing those elements. Maybe this isn't possible (which would be a bummer) but I'm hoping it is and you can point me in the right direction.

    Thanks


    #DashBoard


  • 6.  RE: Dynamic table generation

    Posted 12-20-2021 02:23
    Actually i don't have any idea about Script. so can you please attached that sample file so that i can learn something on it?

    thank you for advance :)

    ------------------------------
    NewBin
    Designer
    ------------------------------