PBR Posted September 27 Share Posted September 27 (edited) Hello, I have a table that includes multiple columns in which one of the columns is named "ID" corresponds to the number of records. I also have a delete button to remove any selected rows from the table. However, the row number under "ID" is getting messed up if I delete a row in between. So, I was looking to update the numbers for "ID" column as I delete the rows. Here is my IronPython script but not sure exactly how to update that. from Spotfire.Dxp.Data import IndexSet, DataValueCursor dataTable = Document.Data.Tables["Events"] markings = Document.ActiveMarkingSelectionReference.GetSelection(dataTable) # Remove the selected rows dataTable.RemoveRows(markings) # Get reference to the 'ID' column idColumn = dataTable.Columns["ID"] idCursor = DataValueCursor.Create(idColumn) rowCounter = 1 # Create an IndexSet to cover all remaining rows after deletion remainingRows = IndexSet(dataTable.RowCount, True) # Update the ID in the remaining rows for rowIndex in range(dataTable.RowCount): if remainingRows.Contains(rowIndex): dataTable.SetValue(idCursor, rowIndex, rowCounter) rowCounter += 1 but I am getting this error: TypeError: expected IndexSet, got int I could update the numbers through a data function and introducing a new column but I am looking to do that through IronPython. Thank you Edited September 27 by PBR Link to comment Share on other sites More sharing options...
Gaia Paolini Posted September 30 Share Posted September 30 could you try adding a calculated column through IronPython to rank the rows? DenseRank(RowId()) Link to comment Share on other sites More sharing options...
PBR Posted September 30 Author Share Posted September 30 Thank you Gaia, I was doing a similar method in data functions, but I want to avoid creating a new column and keep the same column. That would affect the rest of my jobs doing on the table. Link to comment Share on other sites More sharing options...
Gaia Paolini Posted September 30 Share Posted September 30 I tried your script, but no row is actually removed Link to comment Share on other sites More sharing options...
Gaia Paolini Posted September 30 Share Posted September 30 Actually, they are, but my test ID column was calculated as RowId() so it seems to update automatically. Can you show a sample of your data? 1 Link to comment Share on other sites More sharing options...
PBR Posted September 30 Author Share Posted September 30 Yes, my code is removing the row but exactly due to using IndexSet(), I get errors. Could you please share your script that I can see how to use RowId()? Thanks Link to comment Share on other sites More sharing options...
Solution Jose Leviaguirre Posted September 30 Solution Share Posted September 30 (edited) Hello @PBR I think that all you need is to remove the selection and add a calculated column using RowID() dataTable = Document.Data.Tables["Events"] markings = Document.ActiveMarkingSelectionReference.GetSelection(dataTable) dataTable.RemoveRows(markings) The ID column is simply a calculated column. It's custom expression is: RowId() as [ID] Edited September 30 by Jose Leviaguirre 1 Link to comment Share on other sites More sharing options...
PBR Posted October 1 Author Share Posted October 1 Thank you Jose and Gaia. The solution is working now. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now