data table widget - dynamic filter

techies
Kilo Expert

Hi All,

        I am using the data table widget and am wondering if it is at all possible to have the filter reference a variable, i.e. user input. I am not quite familiar with widgets but I know that javascript can be run in the filter (only server side though). If it is not possible I would need to create it myself and any tips on how to approach that would be great too.

Thanks for any help.

1 ACCEPTED SOLUTION

larstange
Mega Sage

Hi



The "Data Table" widget is actually not meant to be use directly - it is meant to be embedded in another widget (eg. Data Table form Instance definition and Data Table from URL Definition). This widget will pass the query and control data to the Data Table widget.



So you just make you own "front-end" widget which have the dynamic filter option you need and then pass the data to the embedded Data Table widget


View solution in original post

11 REPLIES 11

larstange
Mega Sage

Hi



The "Data Table" widget is actually not meant to be use directly - it is meant to be embedded in another widget (eg. Data Table form Instance definition and Data Table from URL Definition). This widget will pass the query and control data to the Data Table widget.



So you just make you own "front-end" widget which have the dynamic filter option you need and then pass the data to the embedded Data Table widget


Hi,


Thanks for the reply that did the trick. I have one more question if you have the time. When the user chooses a value from the sn-record-picker the data table loads correctly with the right filter. However when the user selects another value from the record the data table does not refresh correctly. It just displays "No records in". All the new values are correctly passed to the server I feel as though the problem is just that the widget has troubles refreshing itself. Do you have any suggestions?


Thanks for any help.


robhaas
Tera Contributor

techies, are you able to share what you came up with? Both images/code?


larstange
Mega Sage

Hi



Yes I have seen this happen - It's because when you get the widget model server side via



data.dataTableWidget = $sp.getWidget('widget-data-table', widgetParams);



it only works one time. If you try and refresh the widget via the server it returns an empty data model.



So its a bit of a hack but I have fixed it by



1. Loading the widget model from server the "first time" we render the embedded widget


2. Any subsequent updates to the embedded widget's datamodel is done client side via



spUtil.get("widget-data-table", answer).then(function(response) {


  c.data.dataTableWidget = response;


});