I have a perspective table with a column for pallet weight. I also have some dropdowns that I use for filtering certain columns (like status or part number). I'd like to get the total for those items in the weight column after a filter has been applied. I'm not using table filtering so I can't use filter.results.data. I feel like I might be missing something easy and straightforward.
There's nothing built into the table itself so you're going to have to make your own. The two options I would consider are:
- Write a separate query for the sum using the dropdown values in the WHERE clause.
- Create a binding to the table component's data source and use an expression or script to sum the columns of interest.
That not what I was hoping for, but I ended up going with solution 2. I bound a custom value on the table and did a script transform using the components I use to filter. Only drawback I see right now is that I need to update the transform if I added some additional column filtering to the table.
The custom property binding should detect any change in the table's data property and trigger a re-evaluation automatically. So,
- The table data is bound to the dropdowns. Changing a dropdown selection will refresh the binding on the table data prop.
- The custom prop is bound to the table data. A change in the data will trigger a change in the custom prop.
- The totals display is bound to the custom prop ...
It's the magic of subscriptions!
The SQL query driving the data in the data table isn't based on the dropdowns, the dropdowns are just used to filter the column(s). So when I make a selection in the dropdown, there isn't a change to the table's props.data value. So when I make a selection in the dropdown or change a value in a string input box, I send a message that will do a refreshBinding to the custom prop on the table with the filtered data in it. I have parameters (using len for the number of records and sum for the total weight value) that reference the filtered data dataset and when the filtered data dataset binding gets refreshed these update automatically, so I think everything should be good to go.