Tag dataset filter using from and to time through scripting

I have a dataset in tag
image

it has 2 Columns - displaypath and eventtime

i want to filter the data from tag dataset using from and to time in screen and
pass that in to power tabel

how to achieve it though scripting or any other idea?

I would create a custom method on my power table called getFiteredData(). Then, I would use the propertyChange event scripts on the popup calendars to drive the filtering.

Example:
image

#def getFilteredData(self):
	"""
	Arguments:
		self: A reference to the component instance this method is invoked on. This argument
		  is automatic and should not be specified when invoking this method.
	"""
	#This will have to be changed to your tag path
	tag = '[default]datasetTag' 
	tagData = system.dataset.toPyDataSet(system.tag.readBlocking([tag])[0].value)
	
	#The names and path to your start and end date popup calenders will have to be changed to match yours
	startDate = self.parent.getComponent('Start Popup Calender').date
	endDate = self.parent.getComponent('End Popup Calendar').date
	dateColumnIndex = tagData.getColumnIndex("eventtime")
	headers = list(tagData.columnNames)
	filteredTableData = []
	for row in range(tagData.rowCount):
		if startDate <= tagData.getValueAt(row, dateColumnIndex) <= endDate:
			rowData = [tagData.getValueAt(row, column) for column in range(tagData.columnCount)]
			filteredTableData.append(rowData)
	self.data = system.dataset.toDataSet(headers, filteredTableData)

This following propertyChange event script will have to be added to both popup calenders:

if event.propertyName == 'date':
	#This component path and name will have to be changed to match yours
	event.source.parent.getComponent('Power Table').getFilteredData()

In this way, any time the start or end date is changed, the power table will automatically pull in the filtered data from the dataset tag

2 Likes

Thank you so much its working perfectly

1 Like