# Table selected row looks like selected when table gets updated

**URL:** <https://forum.inductiveautomation.com/t/table-selected-row-looks-like-selected-when-table-gets-updated/105002>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 11, 2025, 3:27pm UTC](https://forum.inductiveautomation.com/t/table-selected-row-looks-like-selected-when-table-gets-updated/105002 "2025-04-11T15:27:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mushu](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mushu](https://forum.inductiveautomation.com/u/Mushu)\
**Post date:** [April 11, 2025, 3:27pm UTC](https://forum.inductiveautomation.com/t/table-selected-row-looks-like-selected-when-table-gets-updated/105002/1 "2025-04-11T15:27:02Z")

</div>

Hi,  
I have a dataset tag.

The dataset data is filtered and shown in a table by a script in a button in perspective.  
When the dataset get updated by a gateway script, the table flickered and cleared.  
To avoid the table getting cleared, three custom properties were added:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/a/2a1268c194ee1261b15346d70979187d0fc20ad2.png)

**FilterValue** = Filter used to filter the data  
**RawData** = holds the Dataset tag, updated via a tag binding  
**FilteredData** = holds the filtered data, updated via the RawData onChange script

This solution fixed the table getting cleared.

But now, if the table has a row selected and the table gets updated, it clears the selected row even though the table looks like it is still selected. Even if you click on the same row again, it doesn’t get selected.

This code then, gives an error coming from **getValueAt().**  
This wasn’t happening before the “get cleared solution” was introduced. This code was able to detect if a row was selected or not but it doesn’t detect that the selected row is cleared on the background:

```python
def runAction(self, event):
    #Logger:
    strLogName = "MoveTrolleyPB"
    log = system.util.getLogger(strLogName)

    Blast_Contents_Table_SelectedRow = self.getSibling("Table").props.selection.selectedRow

    if Blast_Contents_Table_SelectedRow is not None and Blast_Contents_Table_SelectedRow >= 0:
        # --- Read tags 
        ReadTagList = [
            "[Plant_Model]Blast_Contents/Blast_Contents_List",
            "[System]Gateway/CurrentDateTime.value"
            ]
        values = system.tag.readBlocking(ReadTagList)
        Blast_Contents_DataSet = values[0]
        CurrentDT = values[1].value
        # Prepare data:
        # Get a reference to the table component
        table = self.getSibling("Table")
        # Get the table data (list of dictionaries)
        tableData = table.props.data
        # Access a specific column value by its key
        In_trolley = tableData.getValueAt(Blast_Contents_Table_SelectedRow, "Trolley")
        Bl_Moving = True
        ST_Probe = ''
        ST_Blast = ''
        DT_End_Position_DT = CurrentDT
        # --- Write Data Set:
        row = 0
        for row in range(Blast_Contents_DataSet.value.getRowCount()):
            if Blast_Contents_DataSet.value.getValueAt(row, 3) == In_trolley:
                #Write tag
                WriteTagList = [
                    "[Plant_Model]Blast_Contents/Blast_Contents_List[" + str(row) + ",4]",
                    "[Plant_Model]Blast_Contents/Blast_Contents_List[" + str(row) + ",5]"
                    ]
                WriteValues = [ST_Blast, ST_Probe]
                system.tag.writeBlocking(WriteTagList, WriteValues)
                break # Exit loop after finding match
            #endif
        #Next for
    else:
        #Show message: 
        id = 'MessageView'
        view = 'Templates/Message'
        params = {'Message01': 'Please select a row'}
        title = 'Message'
        system.perspective.closePopup(id)
        system.perspective.openPopup(id, view, params, title, showCloseIcon = True)     
    #endif  

```

I read this forum:

> [@Row selected problem in Perspective table](https://forum.inductiveautomation.com/t/row-selected-problem-in-perspective-table/100580):
>
> Hello everyone, I'm going crazy trying to figure out how to fix this issue I'm having with a Table in Ignition Perspective. Basically, when a row is selected (even though the property props.selectedRow: null) doesn't allow it to be selected further, you have to change the row, go back, and then reselect it. I can't figure out how to clear this selection. When I first enter the view, no row is selected, and I’d like to understand which property would allow me to reset the situation to that i…

where pturmel gave this solution:

> The trick is to set enableRowSelection to False, and have a change script on selectedRow looking for None, and then changing enableRowSelection back to True. The code must **not** set enableRowSelection to False when selectedRow is already None.  
> Basically, row selection can only be performed _reliably_ by the client browser. When you disable row selection, that state gets sent to the browser, and **it** clears the selection. When you see that change back in the gateway, you can re-enable row selection.

I have tried to introduce it in my project by:

Phase 1 - Manually

Manually I toggle table property EnableRowSelection

The “selected” row at the table gets cleared

It works!

Phase 2 – Automate it

1. A new custom property was added in the view: EnableRowSelection
2. In the RawData onChange script, the custom property gets reset:

```python
if EnableRowSelection:
    self.custom.EnableRowSelection = False
#endif

```

1. The table property EnableRowSelection gets updated via a property binding with the custom property EnableRowSelection
2. An onChange script is added to the table property EnableRowSelection

```python
    if currentValue.value is False:
        self.view.custom.EnableRowSelection = True
    #endif

```

I can see how the table property EnableRowSelection gets set and reset but it doesn't work. The “selected” row is still selected even though it isn’t.  
Do you know how could I detect that the selection is cleared in the background and how to reselect it?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 11, 2025, 3:47pm UTC](https://forum.inductiveautomation.com/t/table-selected-row-looks-like-selected-when-table-gets-updated/105002/2 "2025-04-11T15:47:31Z")

</div>

> [@Mushu](#):
>
> An onChange script is added to the table property EnableRowSelection

This is wrong. Go re-read my solution.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [April 11, 2025, 4:04pm UTC](https://forum.inductiveautomation.com/t/table-selected-row-looks-like-selected-when-table-gets-updated/105002/3 "2025-04-11T16:04:06Z")

</div>

> [@Mushu](#):
>
> The trick is to set enableRowSelection to False, and have a change script on selectedRow looking for None

That didn't work for me. What worked was having the change script on `selection.data`, not `selection.selectedRow`.

EDIT: Nevermind, I was also explicitly setting selectedRow to None when setting enableRowSelection to False, rather than letting that cause the change in value. It works when I remove that, but in either case, it seems putting the change script on `selection.data` also works.

---

<div class="post-metadata">

**Author:** ![Mushu](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mushu](https://forum.inductiveautomation.com/u/Mushu)\
**Post date:** [April 11, 2025, 4:11pm UTC](https://forum.inductiveautomation.com/t/table-selected-row-looks-like-selected-when-table-gets-updated/105002/4 "2025-04-11T16:11:43Z")

</div>

My apologies pturmel.  
You are right, the onChange script should be in selectedRow, not in enableRowSelection.  
Thank you pturmel and Ryan\_Dearforff

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 11, 2025, 4:15pm UTC](https://forum.inductiveautomation.com/t/table-selected-row-looks-like-selected-when-table-gets-updated/105002/5 "2025-04-11T16:15:14Z")

</div>

> [@Ryan\_Deardorff](#):
>
> seems putting the change script on `selection.data` also works.

I vaguely recall there was a reason I didn't do that, but I don't recall why. 😕
