Jump to content
We've recently updated our Privacy Statement, available here. ×

Select Specific Rows to Form Another Table


Pei Hsuan Shen

Recommended Posts

When I type the program below. It shows that "TypeError: expected DataTableDataSourceUpdateBehavior, got RowSelection".But I refer to the API documentation. The version of the DataTableDataSourceUpdateBehavior and RowSelection is too old to use. (I am using version 10.0.) What can I do to write the code to get the filtered rows to form a tableCan someone tell me how to rewrite the code between ### and ### Thanks.

from Spotfire.Dxp.Data import DataFlowBuilder, DataColumnSignature, DataType, DataSourcePromptMode, IndexSet, DataValueCursor

from Spotfire.Dxp.Data.Import import DataTableDataSource

#Define table name

table = Document.Data.Tables['cloth']

priority = ['XXL', ' XL', ' L', ' S', ' M']

RowCount=table.RowCount

rowsToInclude=IndexSet(RowCount,True)

size = DataValueCursor.CreateFormatted(table.Columns["size"])

for item in priority:

count = 0

for row in table.GetRows(rowsToInclude,size):

rowIndex = row.Index

if size.CurrentValue ==item:

count += 1

if count == 1:

#########

cursor = table.Select(" = " + item)

table=DataTableDataSource(table,cursor)

break

#########

else:

if item == 'Z' and count > 1:

#########

cursor = table.Select(" = ' '")

table=DataTableDataSource(table,cursor)

#########

else:

pass

Link to comment
Share on other sites

You can use below iron python scripts to create another data table using filtered rows:

https://community.spotfire.com/wiki/how-add-new-data-table-based-existing-data-table-analysis-tibco-spotfirer-using-ironpython

https://community.spotfire.com/wiki/how-create-data-table-based-filtered-rows-another-data-table-tibco-spotfirer-using-ironpython

Your script would not work as you are passing Rowselection object instead of DataSelection

Link to comment
Share on other sites

from Spotfire.Dxp.Data import DataFlowBuilder, DataColumnSignature, DataType, DataSourcePromptMode, IndexSet, DataValueCursor

from Spotfire.Dxp.Data.Import import DataTableDataSource

#Define table name

table = Document.Data.Tables['cloth']

priority = ['XXL', ' XL', ' L', ' S', ' M']

RowCount=table.RowCount

rowsToInclude=IndexSet(RowCount,True)

size = DataValueCursor.CreateFormatted(table.Columns["size"])

for item in priority:

    count = 0

    for row in table.GetRows(rowsToInclude,size):

        rowIndex = row.Index

        if size.CurrentValue ==item:

            count += 1

    if count == 1:

#########

        cursor = table.Select(" = " + item)

        table = Document.ActiveMarkingSelectionReference.SetSelection(cursor,table)

        break

#########

    else:

        if item == 'Z' and count > 1:

            #########

            cursor = table.Select(" = ' '")

            table = Document.ActiveMarkingSelectionReference.SetSelection(cursor,table)

            #########

        else:

            passSorry, I don't know how to use the documentation you recommend. But I just replace             table=DataTableDataSource(table,cursor)with             table = Document.ActiveMarkingSelectionReference.SetSelection(cursor,table). But no rows be selected. Is it still my syntax error or something else I don't know how to judge it. Can you tell me Thanks. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...