# Highlighting the last row inserted into a table

**URL:** <https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378>\
**Category:** Ignition\
**Created:** [April 28, 2014, 12:15pm UTC](https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378 "2014-04-28T12:15:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [April 28, 2014, 12:15pm UTC](https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378/1 "2014-04-28T12:15:45Z")

</div>

I am generating a table dataset, i have a button that adds a new row. I would like to have this new row highlight once its inserted but its never on the top or bottom of the list.

What would be the best way to highlight the last inserted row into the table? I do have the ID that I insert into the table but i don’t see how I can find or search the dataset to select that specific row.

Any suggestions would be great, thanks!

Drew

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [April 28, 2014, 1:25pm UTC](https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378/2 "2014-04-28T13:25:34Z")

</div>

Id probably add another column and put a 1 in it, then do a background color based off of that new column. You would just have to make sure and go set the previous column that had a 1 to 0.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [April 28, 2014, 2:51pm UTC](https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378/3 "2014-04-28T14:51:57Z")

</div>

I might just pull the data out of the dataset, parse it and find the ID that was inserted, get the number of the row and then make that the highlighted row.

I’ll let you know what i find

Thanks

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 28, 2014, 3:41pm UTC](https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378/4 "2014-04-28T15:41:23Z")

</div>

Hi drewdin,

By highlighted, do you mean having the row selected? Or do you mean having the background color of the row changed?

Nick Mudge  
Ignition Consulting  
[nickmudge.info](http://nickmudge.info)

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [April 28, 2014, 8:05pm UTC](https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378/5 "2014-04-28T20:05:07Z")

</div>

I am just trying to highlight the newly inserted row, What i have works but there is a timing issue between the row being inserted and the data in the table updating.

I am always behind by the row inserted, it shows in the table but my script does not show the inserted row.

Any suggestions? Thanks again

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 28, 2014, 8:11pm UTC](https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378/6 "2014-04-28T20:11:56Z")

</div>

There are two ways to highlight a row. By making a row the currently selected row, or by changing the background color of a row. Which do you want? Or is either fine?

Is it correct that the table has an ID column that uniquely identifies each row? When a new row is inserted do you also get the ID of the newly inserted row? Or do you need to check the table for a new ID?

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [April 28, 2014, 8:40pm UTC](https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378/7 "2014-04-28T20:40:43Z")

</div>

You are correct, I am inserting a row into a DB, getting the key back from the insert. The first column of my table has this ID.

I’m looping through the table dataset, looking at column 0 for the ID that was just inserted. When the script ends, no rows are highlighted but i can see the new row in the table. I am printing out each row and i don’t see the recently inserted ID.

I am doing a data refresh of the table and a 1 sec delay before my iteration and i still cant see it.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 28, 2014, 9:00pm UTC](https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378/8 "2014-04-28T21:00:05Z")

</div>

Thanks for the details.

I implemented a solution that works.

I added a custom property called ID on a table.

I have a button that when pressed does a database insert and assigns the unique ID of the new record to the table’s ID property. So the actionPerformed script on the button looks like this:

```auto
query = "INSERT INTO Line (ParentID,Name,TimeStamp) VALUES (?,?,NOW())"
id = system.db.runPrepUpdate(query, [4,"test"], getKey=True)
event.source.parent.getComponent('Table').ID = id
```

The table has a database binding to the Line database table. The query is automatically refreshed every 5 seconds.

I added the following propertyChange script to the table:

```auto
if event.propertyName == "data":
	for i in range(event.source.data.rowCount):
		if event.source.data.getValueAt(i,"ID") == event.source.ID:
			event.source.selectedRow = i
```

When the button is clicked a new record is inserted and within 5 seconds the table is updated with the new row and it instantly becomes highlighted.

Nick Mudge  
Ignition Consultant  
[nickmudge.info](http://nickmudge.info)

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [April 29, 2014, 1:47pm UTC](https://forum.inductiveautomation.com/t/highlighting-the-last-row-inserted-into-a-table/8378/9 "2014-04-29T13:47:31Z")

</div>

that worked great, thanks for the help!
