I am trying to follow the posts Using script to add a button to a table row and Pass parameter into embedded view table to add a button to my table in Perspective. I am using a Named Query for my table data and I have a script transform on that data that converts it into a pyDataSet and appends the rows data (as key/value pairs) to an array which I return. Using the columns property, I have made sure to create a column for each key in the pyDataSet. I have also created an additional column for my button. On that column, I changed the render dropdown from auto to view and configured the viewPath to point to a newly created view that contains the button I would like to display in the table cell of the main view. For each row, I only want this button to be displayed if the text in the status column of the table is equal to "PASS". In the newly created view I have an incoming parameter called status. I am expecting the value to be passed automatically from the table and I have the buttons visibility bound to the incoming status parameter. For that I am using an expression binding: if ({view.params.show_button} = "true", true, false). I think I must be missing something. If I don't have the visibility of the button bound, the button appears for every row in the table regardless of the status column. If I add the visibility binding, the button is removed for every row in the table. Can someone help me out please?
The nested view for a column renderer only gets two automatic parameters:
value, the source value for the column containing that view.
rowData, the complete row of data.
If I were you, in your transform, I'd populate the column for the nested view with a boolean reflecting PASS or not. Then the view itself can use self.view.params.value to drive the button visibility.
If you really need other items from the row, you must name a parameter rowData to get the row.
When subviews are enabled for each row in a table, the row will implicitly pass some parameters over to the subview. The passed parameters are:
row - a number representing the row
rowIndex - a number reepresenting the index of the current row
value - JSON Object representing the contents of the row. The value of each column in the row will be a value under this object.
Thus, in the image above where our table has a county column, the subview will receive the value of county at params.value.country. So you can create a component binding on the subview's configuration that references a value at params.value.country.
So, if the column you are using to control the visibility is "show_button", then your button visibility expression becomes something like, {view.params.value.show_button}
Anywhere you have, if ({view.params.show_button} = "true", true, false)
It can be reduced to {view.params.show_button}
which will return a true or false itself.
Thanks, Phil. I got mixed up and did a trawl through the manual looking for it. I can't remember now, does the row value not get passed to the rendered view as well? (I've successfully used subviews and render mode : view in the past.)
I've also added a label right next to the button. I am trying to use the label to display the status as text in the Table column cells. In the Edit Binding preview for the label, I see the word "value" but when I look back at the Table component, all the rows are still missing the button and the label text for the cells is "null". I know for a fact that there is at least one row with status of PASS and the button should be shown for that row.
@Transistor I've taken a look at Displaying a Subview in a Table Row and I've also looked at Perspective - Table | Ignition User Manual. I've made sure that the spelling and case match the column names in the transform and I've unsuccessfully tried using the rowData input parameter by adding a "rowData" key/value pair. I've also tried creating an object named "rowData" and adding key/value pairs to it, but the Designer will not let me name the key/value pairs.
Thank you for the feed back @pturmel. In the view that contains the button (I'll call it buttonView), I've renamed the input parameter to rowData. It still has the two key/value pairs (show_button and status).
Just to be clear, I am expecting rowData to be passed automatically, so in the main view (the one with the Table component) on the column that needs to display the button (via embedded view), I do not have any viewParams.
It is my understanding that for whatever column name that is configured for the Table.column.field property, its associated data will be passed as the value parameter to the buttonView and I should be able to access that using an Expression binding such as if({view.params.rowData.status} = "true",true,false), for example. I am still not able to access the parameters values as expected.
I feel like using the rowData parameter instead of value is the way to go. I just need to get over this parameter passing hump.