Ignition Perspective Table Add/Delete Rows

Hi All,

I am using button to add/delete rows in Table in Perspective.

I am using code below but its not working

data = self.getSibling("Table").props. Data
newRow = {'EQUIP_NOS': '', 'EQUIP_NAME': '', 'EQUIP_STATUS':'','PLANT_SECTION':'', 'SCHEDULE_TYPE':'', 'OPERATOR':''}
data.append(newRow)
self.getSibling("Table").props. Data = data

I am getting error
File "function:runAction", line 4, in runAction
AttributeError: 'com.inductiveautomation.ignition.gateway.datasourc' object has no attribute 'append'

Please use the </> button to format your code so we can read it clearly.

Also, we need to know how you are populating the table.

Where are your binding and to what? (for the data)

the error is clear you are. append isn't working. But we have to get to the root of how you are doing this for an answer.

Is it a static table? If it's dynamic, you will have to script it differently. If it's a query you will need to be updating the database.

1 Like

self.getSibling("Table").props.data is not the type of object you are expecting.

As @andrews says though, we will need to know how you have configured the table to be able to truly help you arrive at an answer.

1 Like

The data type (dataset) of the dataset returned by self.getSibling("Table").props.Data has no method .append() (append is typically for a list type, which this is not). Most likely you want to use system.dataset.addRow()

By default this prop is an Object Structure, so unless there is a binding that is converting the type to a dataset it's probably not a dataset. If there is a binding to a dataset, then what really needs to be done is an update to where ever that data is being pulled from.

1 Like

Thanks All,
I want add/ delete rows for table stored in Sql Lite Database
I am using name query to access Asset_Data Table which is empty now.
After using name query "SELECT * FROM Asset_Data" , i got all columns in table which i have created in Asset_Data table.
But now all are empty. So i want to add row by button then i will enter data and must be stored in table in Sql Lite Database

Hard to give an example without knowing the data. Also this shows you are not providing all your code.

Please provide your full script. So we can see how you query, what you do with it etc...

Where is your query, and where is your script?

Presumably you will need to run an update query to change the table while passing in params.

You'll need to use a property change script to run an update query to add/remove rows from your database.

Hi Andrewa,

Please see image below.
image
On Data, i configured named query as per below image.


Table is empty now. So i want to add row after click on button and then enter details that also need to stored in Asset_Data table

A word of caution. SQL Lite is not really meant for a production environment. If you are looking for a free DB you can use PostgresSQL or MongoDB. If this is intended for a production environment I would strongly recommend you get a more powerful DB package.

To add a row to the table you will need to run an Insert query.

Probably the simplest way to achieve this is to create a Named Query for the insert and then call it from the onActionPerformed event.

I would recommend naming queries in a way that lets you know what they do. For instance I see that you have named your query "query". But with out looking at the actual query there is no way of knowing what that query does. Is it selecting data, inserting data, updating data, or deleting data? What data is it working on?

Something like "getAssetData" or "selectAssetData" is a much better name. It tells the programmer what is happening without needing to know the how of it.

So in this case, you will need an Insert query to add a non existing row, so a name like "insertNewAssetData" is appropriate.

The query will look something like:

INSERT INTO Asset_Data
VALUES (value1,value2,value3,....)

NOTE: You will need a value for every column in the table. Value1 will be inserted into Column 1

Then in the buttons onActionPerformed event, configure a script action where you collect the information and then run the named query using system.db.runNamedQuery()

If you want to update an already existing row in the table, then you will need to run an UPDATE query.

1 Like