# \[IGN-14601\] Database Query Browser can destroy table records when editing sorted data

**URL:** <https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611>\
**Category:** Ignition\
**Created:** [October 21, 2025, 12:12am UTC](https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611 "2025-10-21T00:12:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 21, 2025, 12:12am UTC](https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611/1 "2025-10-21T00:12:00Z")

</div>

v8.1 / v8.3

A colleague found out the hard way that if you sort the result set from a query in the DB query browser and then edit the records and apply them, the edits are applied to the same selected _**indexes (not ids)**_, of the _unsorted_ table data. I.e. it will most likely edit the wrong records 😵

This could be catastrophic for your table data.

Note in the screen capture the critical part is sorting the field, in this case the "name" field so that it reorders the data.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 21, 2025, 3:51pm UTC](https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611/2 "2025-10-21T15:51:03Z")

</div>

Dang, this is one of the oldest bugs I've seen in a while; the affected parts of this code haven't changed since we switched from another VCS system to git in _2011_. And after all that time it's the classic Swing model index vs view index bug.

---

<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:** [October 21, 2025, 3:54pm UTC](https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611/3 "2025-10-21T15:54:55Z")

</div>

Huh. I never noticed that it was even **possible** to edit in the designer query browser result sets.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 21, 2025, 3:55pm UTC](https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611/4 "2025-10-21T15:55:47Z")

</div>

The edit button only enables if we detect the result set has a 'primary key' field we can use to correlate the edits back.

---

<div class="post-metadata">

**Author:** ![ISDProj](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@ISDProj](https://forum.inductiveautomation.com/u/ISDProj)\
**Post date:** [June 30, 2026, 1:45am UTC](https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611/5 "2026-06-30T01:45:52Z")

</div>

Is there a fix coming for this? I ask because it affects Power Table data when sorted too I believe?  
mostly when attempting to ensure a selected row is visible.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 30, 2026, 4:21pm UTC](https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611/6 "2026-06-30T16:21:55Z")

</div>

The issue described on this thread has nothing to do with the power table; the power table doesn't do anything to your database you didn't script it to do.

---

<div class="post-metadata">

**Author:** ![ISDProj](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@ISDProj](https://forum.inductiveautomation.com/u/ISDProj)\
**Post date:** [June 30, 2026, 8:33pm UTC](https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611/7 "2026-06-30T20:33:36Z")

</div>

Thanks for the clarification @paul-griffith - It was just that I wasted quite a bit of effort simply trying to get a sorted power table to ensure the programmatically selectedRow was always made visible. I ended up resorting to the jidetable methods to get it to function as desired. The only reason I even messaged here was because of your:

> [@paul-griffith](#):
>
> And after all that time it's the classic Swing model index vs view index bug.

statement, which turns out to be almost the exact same one that was causing my problem.

In case anyone else stumbles across this thread with a similar issue this is my exact fix:

```python
if event.propertyName == "selectedRow":

#### Do your selected row change logic here first then

# Using invokeLater fixes the timing bug where the UI hasn't painted the selection yet
def scrollTable():
    jideTable = event.source.getTable()
    selectedRowView = jideTable.getSelectedRow()
    if selectedRowView != -1:
        cellRect = jideTable.getCellRect(selectedRowView, 0, True)
        jideTable.scrollRectToVisible(cellRect)

system.util.invokeLater(scrollTable)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 30, 2026, 9:25pm UTC](https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611/8 "2026-06-30T21:25:48Z")

</div>

Jide tables have a `scrollRowToVisible` method.

Try:  
`event.source.table.scrollRowToVisible(event.newValue)` or maybe  
`event.source.table.scrollRowToVisible(event.source.rowIndexToModelIndex(event.newValue))`

---

<div class="post-metadata">

**Author:** ![ISDProj](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@ISDProj](https://forum.inductiveautomation.com/u/ISDProj)\
**Post date:** [June 30, 2026, 11:14pm UTC](https://forum.inductiveautomation.com/t/ign-14601-database-query-browser-can-destroy-table-records-when-editing-sorted-data/111611/9 "2026-06-30T23:14:43Z")

</div>

I did try those from memory... I did try many forms, but what I noticed was that:

> rowIndexToModelIndex(event.newValue)  
> convertRowIndexToView(event.newValue)  
> convertRowIndexToModel(event.newValue)

all returned exactly the same value as the event.newValue whether sorted or not.

I just tried both of your suggested forms of scrollRowToVisible() in the property changed and as an invoke later and neither work if the table has column sorting active and sorted by any column. (FYI the underlying dataset doesn't have a "primary key" as such if that makes a difference?)  
I'll stick with what I have that is working, but thanks anyway for the suggestion.
