Clearing a dataset?

I am creating a dataset to display information in a table. When i am done, i would like to clear or delete all rows in the dataset. what is the best way to do this?
I can use system.dataset.deleteRow() but then i need to know how many rows are in the dataset and i can’t figure out how to get that either?
Thanks for the help.
Scott

Do you really need to clear the dataset or can you just set the tables data property to a new empty dataset?

As Kevin suggests, it looks like the dataset clears itself (after populating the table.data) so there is no need to “clear” the dataset. Nonetheless, if you need the number of records in the dataset you can use the len function after converting to a PyDataSet:

numOfRecords = len(system.dataset.toPyDataSet(table.data))

…or you could clear the table by creating a “blank” dataset:

blankHeader = []
blankDataSet = []
table.data = system.dataset.toDataSet(blankHeader, blankDataSet)

This is all based on Ignition 7.5.6.

2 Likes

Thanks, both are useful.
I have another question regarding populating the table (dataset).
I have a bunch of tags in various folders, the tags are simply numbered 1, 2, … 60, etc. Not all folders have all 60 tags.
Currently i pass the folder path and then loop through the 60 possible tag names and add it to the table if the tag exists. This works but is very slow, i assume due to the use of .TagExists function.
Can you suggest a better way to populate a table with all tags in a folder?
Thanks,
Scott

how about using system.tag.readAll? save all of your folder names in a database table, then write a script that will generate all of the possible tagnames and put them into a string sequence. from there run something like this*** I reread your post and I cant tell if you wanted to just check the tags in 1 folder or in every folder in your system. If you just want 1 folder it would be even easier, you wouldnt need to have the folders in the database at all.***

[code]
tags = [“test”, “test1”, “test123”]

values = system.tag.readAll(tags)

for x in range(len(tags)):

print “%s = %s” % (tags[x], values[x])[/code]

and it will give you this

test = [false,Good]
test1 = [100000,Good]
test123 = [NULL,Not Found]

you can then loop thru and dump anything that is “Not Found” and then send the tagpaths to your dataset. I havent used the tagexists function but my guess is that it calls each tag individually, which is the reason it takes so long.

Thanks for the good suggestion, it does work better and i am going to use it but unfortunately still does work that well (still slow) only because not only do i need the tag value but i also need its .AlertDisplayPath. i need this information to describe the point to the user as the path really does not mean much to them.
the only way i know to get the alertDisplayPath is:
system.tag.getTagValue(tags[x] + “.AlertDisplayPath”)

once i add that line of code the update goes from immediate to several seconds, still better than using the tagexists function which was several seconds x 2!

Still open to any other suggestions.

Thanks for the help.

[quote=“scott_rister”]Thanks for the good suggestion, it does work better and i am going to use it but unfortunately still does work that well (still slow) only because not only do i need the tag value but i also need its .AlertDisplayPath. i need this information to describe the point to the user as the path really does not mean much to them.
the only way i know to get the alertDisplayPath is:
system.tag.getTagValue(tags[x] + “.AlertDisplayPath”)

once i add that line of code the update goes from immediate to several seconds, still better than using the tagexists function which was several seconds x 2!

Still open to any other sug[/quote]

yes you would want to look at using system.tag.getTagValues or system.tag.readAll. if you use system.tag.getTagValue it will make a call for each tag, which if I remember right takes about 60 ms per tag. if you use 1 of the 2 that I mentioned it will pull all of the tags in 1 call. its pretty extraordinary. Ill try to remember to throw you a few examples of using those scripts.

try something like this

query = "select displayname, devicename FROM junk"
if event.propertyName in ["devices", "refresh"]:

   newData = []
   header = ["Displayname", "Devicename", "tag1", "tag2", "tag3", "tag4", "tag5"]
   res = system.db.runQuery(query)
   tagPaths = []

   for row in res:
       tagPath = row[1]
   
  	  
       tagPaths.append("%s/tag1"%tagPath)
       tagPaths.append("%s/tag2"%tagPath)
       tagPaths.append("%s/tag3"%tagPath)
       tagPaths.append("%s/tag4"%tagPath)
       tagPaths.append("%s/tag5"%tagPath)
	   

            
   results = system.tag.getTagValues(tagPaths)
   
   idx = 0
   for row in res:
       displayName = row[0]
       tagPath = row[1]
       newData.append([displayName, tagPath, results[0+idx], results[1+idx], results[2+idx], results[3+idx], results[4+idx]])
       idx += 5

system.gui.getParentWindow(event).getComponentForPath('Root Container.Table').data = system.dataset.toDataSet(header, newData)

I want to display a message when no data on table component, something like below but it’s not working, plz let me know how to mention for table if nodata

if (LotId!="" or MatlAutoId!=None) and vtable==dataset[0x6]:
		self.props.emptyMessage.noData.text="No Data Found"
		self.props.emptyMessage.noData.icon.path=material/sentiment_very_dissatisfied
	else:
		pass

4 posts were merged into an existing topic: Display custom message when Perspective Table has no data

Great way and more readable. I just did this due how easily it was to implement. Thanks for your input!

	# clear table and wait 1 second, to show user things are happening
	self.getSibling("RandomTagTableName").props.data = ""
	time.sleep(1)

This is the opposite of showing a user things are happening.
Consider toggling the visibility of an icon, and/ or animating it with CSS so that the page conveys action instead of appearing to be frozen with data suddenly missing.

2 Likes