Jump to content
  • Use IronPython to Set a Custom Sort Order in Spotfire®


    Spotfire® has the ability to set custom sort orders - that is whereby the values in a column can be ordered other than the natural string order or numerical order. It's often useful to be able to set a custom sort order using code - that way, you can algorithmically decide the sort order - for example, to deal with values that are not known at design or authoring time.

    Introduction

    Spotfire® has the ability to set custom sort orders - that is whereby the values in a column can be ordered other than the natural string order or numerical order. It's often useful to be able to set a custom sort order using code - that way, you can algorithmically decide the sort order - for example, to deal with values that are not known at design or authoring time.

    Here are some examples for setting a custom sort order using IronPython.

    Reverse Date Sort Order

    The below script uses a custom sort order to reverse the normal sorting of a date column.

    # Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
    
    from System.Reflection import Assembly 
    from Spotfire.Dxp.Data.Collections import *
    from System.Runtime.Serialization import ISerializable
    from System.Collections import IComparer
    from System.Collections.Generic import IComparer
    
    values = Document.Data.Tables['MY_DATA_TABLE'].Columns['DATE'].RowValues.GetEnumerator()
    myValues = []
    for val in values:
        myValues.Add(val.ValidValue)
        myValues.sort(reverse=True)
    Document.Data.Tables['MY_DATA_TABLE'].Columns['DATE'].Properties.SetCustomSortOrder(myValues)
     

    References

     

    License:  TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...