Jump to content
  • How to apply a regular expression search criteria to a Filter in Spotfire® Using IronPython Scripting


    A regular expression search criteria can be applied to a filter using a python script.

    Introduction

    A regular expression search criteria can be applied to a filter using a python script. The search expression can be any input abiding regular expression rules. This example shows how the search criteria can be applied to a list box filter column.

    Code sample

    # Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
    
    from Spotfire.Dxp.Data import DataValueCursor
    from Spotfire.Dxp.Application.Filters import ListBoxFilter,FilterTypeIdentifiers
    from System import Array,String
    
    search='^E+'
    myTable=Document.Data.Tables["Sales"]
    #Here cname is the name of the required column on which the search expression needs to be applied
    rowSelect=myTable.Select('cname ~= "'+search+'"')
    mycol=DataValueCursor.CreateFormatted(myTable.Columns["cname"])
    values = set()
    for row in myTable.GetRows(rowSelect.AsIndexSet(),mycol):
     v=mycol.CurrentValue
     if v not in values: 
      values.add(v)
     
    my_array=[]
    my_array=list(values)
    
    myPanel=Document.ActivePageReference.FilterPanel
    myFilter=myPanel.TableGroups[0].GetFilter("cname")
    listBoxFilter=myFilter.FilterReference.As[ListBoxFilter]()
    listBoxFilter.IncludeAllValues=False
    if my_array!=String.Empty:
     listBoxFilter.SetSelection(my_array)
    else:
     listBoxFilter.Reset()
     

    References

     

    License:  TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...