# Select row and then filter table by value from a column in that row

**URL:** <https://forum.inductiveautomation.com/t/select-row-and-then-filter-table-by-value-from-a-column-in-that-row/32178>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [February 12, 2020, 5:10pm UTC](https://forum.inductiveautomation.com/t/select-row-and-then-filter-table-by-value-from-a-column-in-that-row/32178 "2020-02-12T17:10:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cody56](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@cody56](https://forum.inductiveautomation.com/u/cody56)\
**Post date:** [February 12, 2020, 5:10pm UTC](https://forum.inductiveautomation.com/t/select-row-and-then-filter-table-by-value-from-a-column-in-that-row/32178/1 "2020-02-12T17:10:33Z")

</div>

Ok so I’m pretty new to scripting in Python and I’m having trouble figuring this one out.

I have a table full of results and every row has a barcode (stored as a string) included. I’d like to be able to open a popup menu on a selected row and then take the barcode value of that row and then filter the table by that value. I’m just completely lost on how I need to structure this event.

Any help or guidance?

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [February 12, 2020, 6:28pm UTC](https://forum.inductiveautomation.com/t/select-row-and-then-filter-table-by-value-from-a-column-in-that-row/32178/2 "2020-02-12T18:28:11Z")

</div>

Basically something like this

```auto
tbl = event.source.parent.getComponent('Power Table')
pDS = system.dataset.toPyDataSet(event.source.parent.getComponent('Power Table').data)
hdr = list(event.source.parent.getComponent('Power Table').data.getColumnNames())
flt = tbl.data.getValueAt(tbl.selectedRow,'BarCodeColumn')
filtered = []
for row in pDS:
	if row['ColumnToCompareTo']==flt:
		filtered.append(list(row))
event.source.parent.getComponent('Power Table').data=system.dataset.toDataSet(hdr,filtered)

```

---

<div class="post-metadata">

**Author:** ![cody56](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@cody56](https://forum.inductiveautomation.com/u/cody56)\
**Post date:** [February 21, 2020, 7:21pm UTC](https://forum.inductiveautomation.com/t/select-row-and-then-filter-table-by-value-from-a-column-in-that-row/32178/4 "2020-02-21T19:21:10Z")

</div>

Ok this is what I eventually got to work and it does what I want.

```
 def filter(event)
	pDS = system.dataset.toPyDataSet(self.data)
	hdr = list(pDS.getColumnNames())
	flt = self.data.getValueAt(self.selectedRow, 'Barcode')
	filtered = []
	for row in pDS:
		if row['Barcode']==flt:
			filtered.append(list(row))
	self.data = system.dataset.toDataSet(hdr,filtered)

menu = system.gui.createPopupMenu(['Isolate Barcode'], [filter])
menu.show(event)

```

However, I have the Power Table.data bound to a Named Query in polling mode. This means that when that poll is executed, the query overwrites my new dataset. Is there a way to manipulate the column filtering directly through scripting?
