Jump to content

How to delete marked rows based on certain condition using IronPython


Andrew Hue

Recommended Posts

Hello there,

I've been trying to find a way to delete a marked row(s) where one of the columns matches a specific value. In this case, I want to allow deleting rows only when a "username" attribute matches the current username.Here's what I have so far:

 

from Spotfire.Dxp.Data import *

from System.Threading import Thread

 

#assign marked rows into variable

selectedRows = Document.Data.Markings["Marking"].GetSelection(Document.Data.Tables["MyTable"])

 

#create data cursor on a the "Username" column

cursor = DataValueCursor.CreateFormatted(Document.Data.Tables["MyTable"].Columns["Username"])

 

#loop through the column rows, then retrieve the values and then check against current username.

for row in table.GetRows(cursor):

value = cursor.CurrentValue

if value == Thread.CurrentPrincipal.Identity.Name:

Document.Data.Tables["MyTable"].RemoveRows(selectedRows)Anyone know the right way to do this

Would appreciate any help!

Thanks.

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

Hi Anthony,

Give this script a shot:

from Spotfire.Dxp.Data import *

from System.Threading import Thread

#assign marked rows into variable

table = Document.Data.Tables["MyTable"]

markedRows = Document.Data.Markings["Marking"].GetSelection(table)

userRows = table.Select("[username] = '%s'" % Thread.CurrentPrincipal.Identity.Name)

set1 = IndexSet(markedRows.AsIndexSet())

set2 = IndexSet(userRows.AsIndexSet())

rowSelection = RowSelection(set1.And(set2))

table.RemoveRows(rowSelection)

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