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

Question on ironPython


Recommended Posts

Apologies, if this already been shared.

This is my need: I need to have a query screen with two buttons, (something like an ID and Name). The User will input value into either of them, and I need to get the matching records from a base table( Data Table in Spotfire).

Would be of great help, if someone can point to similar postings, or if you have done it would be great if you can share it.

Thanks in advance


Link to comment
Share on other sites

First, the title of your question is really too vague :D

Secondly, below there is the code to get the values of the *filtered* values in a given column:

from Spotfire.Dxp.Data import *


main_table_name = "Data Table" # or whatever the name of your table is


def get_column_values(column_name, filtering_scheme_name = "Filtering scheme"):


Gets the filtered (by the filtering scheme) values in the column.



# Specify the data table used in Spotfire

dataTable = Document.Data.Tables[main_table_name]


# Get a reference to the specified filtering scheme on the data table above

dataFilteringSelection = Document.Data.Filterings[filtering_scheme_name]

filteringScheme = Document.FilteringSchemes[dataFilteringSelection]

filterCollection = filteringScheme[dataTable]


# Filtered rows based on the scheme above

filteredRows = filterCollection.FilteredRows


# Specify the column in the data table to get the values

myColCursor = DataValueCursor.CreateFormatted(dataTable.Columns[column_name])


column_data = []


# Iterate over the filtered rows

for row in dataTable.GetRows(filteredRows, myColCursor):

# cursorValue will now contain the value for the column at the current row position

cursorValue = myColCursor.CurrentValue



return column_data



Once you have this, you can create a list of lists containing all the rows that you would like. So, if you want the columns "ID", "Name" and, for example, "Age", you can create this list by doing

data = list(zip(get_column_values("ID"), get_column_values("Name"), get_column_values("Age")))Then, you can retrieve the document properties to which you attached the two inputs in your text area, like so:

id = Document.Properties["ID"]

name = Document.Properties["Name"]and you can filter the "data" list by doing

filtered_data = [elem for elem in data if elem[0] == id and elem[1] == name]Now filtered data contains all the rows with the given id and name.

If you only want to find one, you can also do

selected = next(elem for elem in data if elem[0] == id and elem[1] == name, None)You'll get the first row with the given "id" and "name", or None if no such row exists.


I hope that helps.

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...