Facility Control

 View Only
  • 1.  thousands separator in parameter

    Posted 06-01-2020 03:53

    hi all!

     

    im need dashboar to show integer parameters with thousands separators( like 1,000) intead of 1000.

     

    is this possible?

     

    thanks

    Diego

     



  • 2.  RE: thousands separator in parameter

    Posted 06-01-2020 12:48

    most javascript works in ogscript, so i believe this should do the trick for you. just replace the get/set params to your params.

    var num = params.getValue('numInput', 0);

    num = num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

    params.setValue('numOutput', 0, num);


    #DashBoard


  • 3.  RE: thousands separator in parameter

    Posted 06-01-2020 15:13

    I don't think there's a way to "format" an integer field to show commas.   So the only way to do this is to have a label (or a string parameter) that updates when the integer changes.  That label mirrors what is in the integer parameter, but has a comma inserted.

    Roger's answer above shows how to do this.   I found a similar answer here:

    https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript

     

    With that, I created a quick panel that shows how this would work:

    <abs contexttype="opengear" gridsize="20" id="_top" keepalive="false" style="">
    <meta>
    <params>
    <param access="1" constrainttype="INT_NULL" name="number" oid="number" precision="0" type="INT16" value="10010" widget="default"/>
    </params>
    <context contexttype="opengear" id="Graphite.1" objectid="opengear.devicefiles.misc&lt;br&gt;Slot 1&lt;br&gt;Graphite" objecttype="Graphite"/>
    </meta>
    <param expand="true" height="20" left="80" oid="number" showlabel="false" top="40" width="180">
    <task tasktype="ogscript">function numberWithCommas(x) {
    x = x.toString();
    var pattern = /(-?\d+)(\d{3})/;
    while (pattern.test(x))
    x = x.replace(pattern, "$1,$2");
    return x;
    }


    var valueWithoutComma = params.getValue("number",0);
    var valueWithComma = numberWithCommas(valueWithoutComma);

    ogscript.rename("number_label", valueWithComma);</task>
    </param>
    <label height="20" id="number_label" left="280" style="txt-align:west" top="40" width="220"/>
    </abs>

     

    The limitation on this is that the label (or string parameter) cannot be updated by the user.   It only shows the value.


    #DashBoard