Reseting table data

Hello!

Is it possible to create a button to reset the table data that is recorded until that moment, and start picking up new data from the time I press the button? In other words, I have a table recording 1 hour of realtime data, I want to press a button so that everything from that hour gets erased and it starts to record data from that moment. Could someone help me, please?

Thanks in advance!

Are you just trying to delete all the rows in the dataset but keep the column headers? There are a couple of ways to do this:

clearedDataSet = system.dataset.toDataSet([HeadersList], [])

or

clearedDataSet = system.dataset.clearDataset(OldDataset) #New in 7.9.7

or

clearedDataSet = system.dataset.deleteRows(OldDataset, range(OldDataset.rowCount))
2 Likes

Could you evolve the code a little more? I tried to use what you told, but I couldn’t make it work. So I tried this:

table = event.source.parent.getComponent(‘Table’)
header = [‘t_stamp’,‘PIDT1’,‘PIDT2’,‘PIT1’,‘PIT2’,‘ZIT1’,‘ZIT2’]
row = []
data = system.dataset.toDataSet(header,row)
table.data = data

and everything that happens is that the table erases everything, it’s just a blank table, except the headers. It stays erased for about 1 second, and then the table reappears with all old rows values. I needed something like… set all the rows values to 0, for example… in order to get the new realtime values. Could you help me?

If the data is coming from a binding (DB query, presumably), then you need a script that will modify the data at the source (the DB) or change the parameters of the SQL query. You’ll have to show us the binding you currently have.

Yes, the data is coming from the DB

Or maybe if it’s less complex, I could use a 2 state toggle to set when I want the table to write data or not. For example, I press the button to “ON” state, at 2pm, and it records until I press the button again, at 3 pm. Then, I press it again at 8 pm. The table just shows data from 2 to 3 pm then from 8 pm to something. Is this easier for you to help?

Well, the historian doesn’t have any script support for deleting history, so you’ll have to do it with a post-filter. I would move the history binding to a custom property (rawData, perhaps) and add a Date as another custom property (startDate, perhaps), then bind the table data with a filter on startDate. I’d use the view() function from Simulation Aids, though it could be done with a propertyChange event instead. Something like this (expression binding on data):

view("Select * Where t_stamp >= args[0]",
 {Root Container.Table.rawData},
 {Root Container.Table.startDate})

Then have your button’s script assign the current timestamp to startDate to hide past data.

I’m getting this error

Did you make rawData a Dataset? And did you move your binding from data over to rawData?

Also, I don’t think the old version of the module you’ve chosen to use allows the asterisk (column wildcard). You’ll probably have to spell out all of your column names.

Now it’s working, but everything just goes blank, the table is “gone”. What should I do?

What did you put in the startDate property? No data after that will show up – that’s the whole point. Set it to more than an hour ago and you’ll get your previous data. Set it to “now” (via button script) and the data will disappear, then recent data will appear as time passes.

rawData needs your Tag History binding as shown in your 3rd comment, and as I already stated in my 2nd and 3rd comments. What was originally bound to data. The view() method will take that dataset and filter it to exclude rows older than startDate.

1 Like

hey hi
can u help me in 1 script . where i have a table in ignition from mysql and adding the rows from ignition from translational list and after adding the rows in table becomes zero.? is this possible

i want a help a from u guys.
actually i hava a table in ignition from mysql DB wwithout any rows and i wanted to add the rows in database from table only. ex im able to add value in table after tapping the add button all data should push it the mysql database after that rows in the ignition table becomes zero.

This should really be in it’s own topic.

In the meantime, this should point you in the right direction for moving a dataset into a database:

How to clear a dataset:
https://docs.inductiveautomation.com/display/DOC80/system.dataset.clearDataset