Jump to content

Get filtered values from a column - IronPython


Priyank Dwivedi

Recommended Posts

I would like to get filtered values from a column in IronPython

The below code somehow gives me 'ALL' values from a column instead of filtered values.

Can someone suggest what am I doing wrong?

import clrclr.AddReference('System.Data')from System.Data import SqlClientfrom Spotfire.Dxp.Framework.ApplicationModel import NotificationServicefrom Spotfire.Dxp.Data import DataColumn, DataType, DataTablefrom Spotfire.Dxp.Application.Filters import FilteringSchemefrom Spotfire.Dxp.Data import DataSelectionfrom Spotfire.Dxp.Data import *from System.Collections.Generic import Listfrom Spotfire.Dxp.Data import DataValueCursorfrom Spotfire.Dxp.Data import RowSelectionfrom datetime import datetimefrom System.Collections import ArrayListfrom System.Threading import Threadfrom Spotfire.Dxp.Application.Filters import ListBoxFilter   def getFilteredItemValues(dataTable, filterObject, columnName): itemList = []  filteredRows = filterObject.FilteredRows  myColCursor = DataValueCursor.CreateFormatted(dataTable.Columns[columnName])  for row in dataTable.GetRows(filteredRows,myColCursor): # cursorValue will now contain the value for the column at the current row position cursorValue = myColCursor.CurrentValue itemList.append(cursorValue)  return itemList # define Column...colName = "Api_No14" #get a reference to the listbox columnfilt=Document.FilteringSchemes[0][myDataTable][myDataTable.Columns[colName]].As[ListBoxFilter]() # Get ValueswellList2 = getFilteredItemValues(myDataTable, filt, colName)print(wellList)

Link to comment
Share on other sites

You refer to dataTable and to myDataTable in the script. If I substitute every "dataTable" with "myDataTable" (input parameter for my chosen data table) if works for me. Did you mean to have two separate data tables?

Also minor problem, change the last line to print(wellList2) to avoid error.

If you want to print only the unique values, it is more convenient to use print(set(wellList2))

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