Using script to add a button to a table row

Hello All,

I am still a little new to Ignition, so please be kind. I have written a script in perspective that queries a database and uses the result set to populate an empty table that is contained in another view. I would like to add a button to one or more of the table rows. I have not been able to find an example of this being done. If this is possible, can someone please point me in the right direction?

Kind regards

It sounds like this could be helpful.

  1. Add in a column into your data (can be inside the query or in a transform script). Its best to give it a meaning full value that can be used for whatever script you want to run in the button (so an id?)
  2. The append the props.column property of the table to the number of columns you have each with a fieldname coresponding to the data.
  3. Make a view with a simple button. Best to give it a param: “value” and “rowIndex”, thes will automaticcaly be bindend to the value/rowId of the column you will pass in here, so it can be used to run a dynamic script
  4. For the column you want a button you will have to put the viewpath into the viewpath property there.

(i used some labels to show the params work)

Thank you for replying victordcq

I am trying to follow your steps but I need some help clarifying a few things. First, let me mention that I am using a column value to determine if I should be showing my button as I loop through the rows in my data. In step 2 of your response, I think you are saying that I should use the designer to create columns in the table so they match the data that is coming in. For step 3, I have made a view that contains a button. But I am not clear on how I should be populating the parameter values. In the table, I have set the view path for the column which should be displaying the button to access the view that contains my button. I am able to see the data but I can not see my button. Can you help me figure out what I am doing wrong?

  1. yes thats fine, be sure to add in a value for the button column on all data tho.You could give it true or false to deterime the display/visibilty of the button^^
  2. yes in the designer you will see the table have a property named ‘columns’ you will have to add objects to the array there and apoint the right field for every column and for the button also fill in the viewPath, just like in my screenshot (the yellow marked things)
  3. the Params value and rowIndex (and a few others see docs) automatically get populated by the table, no need to put them into viewParams
    4.idk can you show me what you got?

Thank you so much! I was able to get it to work by also switching the render property from “auto” to “view”. The only problem that I have now is I cannot stop the button from appearing for each row. The data that populates the table has two columns. One of them has a bit datatype which. In the table, I have set the viewPath property on the column that is populated by the bit data. But I think I want actually be doing is setting the viewPath on the cell instead as @zacht suggests. With that said, I am having difficulty adding the view to the cell. I realize that Tables cannot be changed and a copy will be created. So I am taking my original data and converting it to a PyDataSet then looping through the rows. My plan is to determine which row of the bit column is 1 “true” while looping the rows and once I find one of those rows, I access the same row/column in the table and add a view to it (Please let me know if there is an easier way) . I have tried to adding the view to a cell using[rowNum][columnNum].viewPath = “”. Which throws an error. I’ve also tried looking at table.props.rows and table.props.cells but I still can’t seem to get the view to appear “only” where I want it to be. Do you (or anyone else) have any suggestions that I might try?

That doesnt sound like a good idea.
There is a “value” parameter that gets passed down to the view. Just pass this ‘bit’ value down along it. And bind it with visiblity on the button.

1 Like

I wasn’t quite sure how to pass the value, but after viewing this post (Pass parameter into embedded view table - #7 by cmallonee) I was able to get everything working the way that I want. Thanks so much for all of your help!

1 Like

@victordcq , @israel.jordan I have added a column into my table manually. I have also changed the render prop to view and passed a view path to the viewPath prop. However, it didn’t show the button column on my table. Besides this, the population and country columns from the original data were invisible.

Thank you for your time.

All your data also needs a field that is named like the props.
It doesnt look like you have that as it is showing the column city. Change the property columns[0].field to city should render the view

1 Like