Jump to content
  • IronPython Sort Columns in Spotfire


    How to sort columns custom order using IronPython

    Introduction

    Sometimes we want to give the user the ability to sort the column order from the WebPlayer or a guided analysis where the sorting from Data > Column Properties > Sort Order is not available for the end user. In this article we discover how this is done using the power of IronPython

    DataTable.jpg.d541da91afe905bd65063eff719150b5.jpg

    Customproperties.png.4eeaf392a587144c3bc3248cd2daf190.png

    Create and test the script

    Step 1

    On a Text Area, Create a List box (multiple select) Property Control with Unique values in column pointing to a new String List Document Property called "values"

    Step 2

    Create a Label Property Control on a Text Area using the "values" document property to output the selecting order of the columns and add a "Apply" Action Control Button

    Step 3

    Create an IronPython script for the Apply button

    #tblName and colName can be script parameters
    tblName = "Blood Work"
    colName = "type"
    values = Document.Properties["values"]
    dt = Document.Data.Tables[tblName]
    # The values in values must be of the same type as the values in the column. # Column values not present in values will be sorted last.
    dt.Columns[colName].Properties.SetCustomSortOrder(values)
     

    If you are getting values from another source other than a document property, you can sort the columns this way:

    tblName = "Blood Work"
    colName = "type"
    values = System.Collections.Generic.List[str](["A","B","AB","O"])
    Document.Data.Tables[tblName].Columns[colName].Properties.SetCustomSortOrder(values)
     
     
     

     

    sortcolumns.jfif


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...