# getRowsInViewOrder()

**URL:** <https://forum.inductiveautomation.com/t/getrowsinvieworder/9077>\
**Category:** Ignition\
**Created:** [September 18, 2014, 6:20pm UTC](https://forum.inductiveautomation.com/t/getrowsinvieworder/9077 "2014-09-18T18:20:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zfellers](https://avatars.discourse-cdn.com/v4/letter/z/b19c9b/32.png) [@zfellers](https://forum.inductiveautomation.com/u/zfellers)\
**Post date:** [September 18, 2014, 6:20pm UTC](https://forum.inductiveautomation.com/t/getrowsinvieworder/9077/1 "2014-09-18T18:20:37Z")

</div>

Version: 7.6.6  
OS: Win7

I have a table bound to a SQL query that works great.

`SELECT ID, STRING, t_stamp
FROM TFL{Root Container.CP FAULTS.Line}CPFAULTS
WHERE t_stamp > '{Root Container.CP FAULTS.Date Range.startDate}' AND
t_stamp < '{Root Container.CP FAULTS.Date Range.endDate}'`

I’d like to add an additional dynamic column to simply number the rows and getRowsInViewOrder() appears to be the solution. I’ve attempted to implement a “propertyChange” event script on the table to add this column.

`if event.propertyName == "data":
	system.dataset.addColumn(event.source.data[0], [b]Type PySequence[/b], "Error", [b]Type PyType[/b])
	getRowsInViewOrder()`

I’m not sure how to obtain the appropriate PySequence and PyType arguments in the addColumn function. Maybe there’s an easier way?

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [September 18, 2014, 6:55pm UTC](https://forum.inductiveautomation.com/t/getrowsinvieworder/9077/2 "2014-09-18T18:55:31Z")

</div>

This should work in MySQL.

`SELECT @curRow := @curRow + 1 AS row_number, ID, STRING, t_stamp
FROM TFL{Root Container.CP FAULTS.Line}CPFAULTS
JOIN (SELECT @curRow := 0) r
WHERE t_stamp > '{Root Container.CP FAULTS.Date Range.startDate}' AND
t_stamp < '{Root Container.CP FAULTS.Date Range.endDate}'`

---

<div class="post-metadata">

**Author:** ![zfellers](https://avatars.discourse-cdn.com/v4/letter/z/b19c9b/32.png) [@zfellers](https://forum.inductiveautomation.com/u/zfellers)\
**Post date:** [September 24, 2014, 4:51pm UTC](https://forum.inductiveautomation.com/t/getrowsinvieworder/9077/3 "2014-09-24T16:51:15Z")

</div>

The following query worked under property binding:

`SELECT ROW_NUMBER() OVER(ORDER BY t_stamp) AS Row, ID, STRING, t_stamp
FROM TFL{Root Container.Faults.Line}CPFAULTS
WHERE t_stamp >= '{Root Container.Faults.Date Range.startDate}' AND
t_stamp <= '{Root Container.Faults.Date Range.endDate}'`
