Forum Discussion

FICO's avatar
FICO
Community Manager
8 years ago

Filter vdl-table display to nonzero rows in FICO Insight application

This FICO Xpress Optimization forum might not be the right area for this question, but I don't see a forum for FICO Insight.

I have a FICO Insight application that displays a Mosel entity on the web-based user-interface using a vdl-table. The Mosel entity is mostly zeros though. What's the easiest way to filter the table for the rows that contain at least one non-zero? I'm pretty sure the answer involves vdl-index-filter.

For example, I have the Mosel entities:

Materials_Description: dynamic array(Plants, Materials) of string

rawinput: dynamic array(Plants, Materials, Times) of mpvar

and one of my vdl-page views contains:

<vdl-table page-mode="paged" show-filter="true">

<vdl-table-column entity="Materials_Description"/>

<vdl-table-column entity="rawinput"

                  heading="=col.label"

                  vdl-repeat="=col in scenario.entities.Times">

<vdl-index-filter set="Times" value="=col.value"/>

</vdl-table-column>

</vdl-table>

then I get a nice table with the Times set pivoted, but there are a lot of rows in the table that are entirely zero. How can I filter out those rows?

1 Reply

  • FICO's avatar
    FICO
    Community Manager

    Ok, I found a solution that uses the "row-filter" attribute of the vdl-table.

    I modified my VDL file to:

    <script>

    function absAdd(a, b) {

    return Math.abs(a) + Math.abs(b);

    }

    function nonZeroRow (rowData, indices, otherColumnsToIgnore) {

    // return true if the sum of the data in the row is greater than zero

    // the sum excludes some of the first columns (any index columns plus otherColumnsToIgnore)

    // otherColumnsToIgnore should be an integer

    var rowStart = indices.length + otherColumnsToIgnore,

        rowEnd = rowData.length;

    return rowData.slice(rowStart, rowEnd).reduce(absAdd, 0) > 0;

    }

    </script>

    <vdl-table page-mode="paged" show-filter="true"

               row-filter="=nonZeroRow(rowData, indices, 1)">

    <vdl-table-column entity="Materials_Description"/>

    <vdl-table-column entity="rawinput"

                      heading="=col.label"

                      vdl-repeat="=col in scenario.entities.Times">

    <vdl-index-filter set="Times" value="=col.value"/>

    </vdl-table-column>

    </vdl-table>