How do you add Filter to a table/list during the runtime

Options
newbie321
edited February 11, 2022 in Analytics #1
<p>Hi, </p>
<p> </p>
<p>I need to add a Filter to a table during the runtime.  </p>
<p>I am using the basic setup:</p>
<div>
<pre class="_prettyXprint">
TableHandle th = (TableHandle) DesignHandle.findElement("Table")
FilterCondition fc = StructureFactory.createFilterCond();
fc.setExpr( "row[\"something\"]" );
fc.setOperator(DesignChoiceConstants.MAP_OPERATOR_EQ);
fc.setValue1("something");
PropertyHandle ph =th.getPropertyHandle( TableHandle.FILTER_PROP );
ph.addItem( fc );</pre>
<p>However, the </p>
<pre class="_prettyXprint">
th.getPropertyHandle( TableHandle.FILTER_PROP );</pre>
<p>is returning NULL  and  this makes adding a Filter impossible via:</p>
<pre class="_prettyXprint">
ph.addItem( fc );</pre>
<p>I looked through the forums and the web and it looks like the TableHandle.FILTER_PROP should return something.  </p>
<p> </p>
<p>Anyone knows why the Filter property handle is returning null or is the above implementation already outdated? </p>
<p> </p>
<p>Thanks,</p>
<p> </p>
<p> </p>
<p> </p>
</div>

Comments

  • micajblock
    edited October 25, 2016 #2
    Options
    <p>Take a look at the attached design. It uses a data object so can be run in OpenText BIRT only. Code in beforeFactory below:</p>
    <pre class="_prettyXprint">
    importPackage(Packages.org.eclipse.birt.report.model.api);
    importPackage(Packages.org.eclipse.birt.report.model.api.elements.structures);
    importPackage(Packages.org.eclipse.birt.report.model.api.elements);
    importClass(Packages.org.eclipse.birt.report.model.api.elements.DesignChoiceConstants);


    if (params["Country"].value) {
    var xtab = reportContext.getDesignHandle().findElement("xtab1");
    addXtabFilter(xtab, "\"" + params["Country"].value + "\"", null, DesignChoiceConstants.FILTER_OPERATOR_EQ, "dataSetRow[\"COUNTRY\"]");
    var tab = reportContext.getDesignHandle().findElement("table1");
    addTableFilter(tab, "\"" + params["Country"].value + "\"", null, DesignChoiceConstants.FILTER_OPERATOR_EQ, "dataSetRow[\"COUNTRY\"]");
    }


    // Set Filter for Crosstab Object
    function addXtabFilter(elemHandle,values1,values2,operator,colExpression) {
    var filterhandle = elemHandle.getPropertyHandle("filter"); 
    var ef = reportContext.getDesignHandle().getElementFactory();
    var fc = ef.newFilterConditionElement();
    fc.setOperator(operator);
       
      if (values1)
        fc.setValue1(values1);
    if (values2)
           fc.setValue2(values2);
        
      var expression = new Expression(colExpression, ExpressionType.JAVASCRIPT);
      fc.setExpressionProperty( FilterCondition.EXPR_MEMBER, expression );
      filterhandle.add(fc);
    }


    // Add Filter to elememt (chart, table)
    function addTableFilter(elemHandle,values1,values2,operator,colExpression) {
    var filterhandle = elemHandle.getPropertyHandle("filter"); 
    var fc = StructureFactory.createFilterCond();
    fc.setValue1(values1);
    var expression = new Expression(colExpression, ExpressionType.JAVASCRIPT);
    fc.setExpressionProperty( FilterCondition.EXPR_MEMBER, expression );
    fc.setOperator(operator);
    if (values2 != null)
    fc.setValue2(values2);
    filterhandle.addItem(fc); 
    </pre>
    <div>}</div>
    <div> </div>
  • <p>Attached is a version using OS BIRT and Classic Models</p>
  • <p>Thanks, @mblock!!  </p>
    <p> </p>
    <p>your example worked like a charm!!</p>
    <p> </p>
    <p>Thanks again! </p>