Filtering DataGrid 2 objects with multiple values inserted inside single text field

0
Hello everyone, I ran into an interesting situation recently. I was trying to create a Datagrid 2 text filter containing multiple IDs to display only items in which the id is included in that string. However I was unable to make that happen without adding new associated entity with boolean attribute like shouldBeIncluded for each item, but that not only forced me to make that entity PE (NPE cannot be used in Xpath of the DataGrid2, because this relation would start with with entity which is not persistable <- this is the error I got when trying to do so), but also it means that there is a lot of trash data in my DB. I also don't like the fact I just want these items with shouldBeIncluded attribute to exist when I am filtering the table and sure I could delete them when user changes input, but what if he leaves somehow the page. My DB will start to store more and more leftovers.Is there any legitimate way to approach this? What I want is to write in my ItemId filter something like: 1,2,3,4,5 and then for DataGrid2 to only display objects with IDs: 1,2,3,4,5. Thanks for all the help!   PS. I need to keep Datasource as Database, because I am using pagination etc.
asked
1 answers
0

The basic idea is to tie the filter data to the current user (or even to a single page visit) and reset it whenever the page is opened. You can model FilterSession and FilterId as persistent entities and link them to System.User, so each user only ever works with their own filter data.

 

On the page’s On Page Load microflow, you simply clean up first: find any existing FilterSession records for the current user and delete them together with their related FilterId rows. If you want, you can immediately create a new, empty FilterSession so the page always starts in a known, clean state.

 

When the user types something like 1,2,3 into the filter field and clicks an Apply button (or triggers an On Change action), a microflow parses that string, clears the old FilterId entries for the current session, and creates new ones for each parsed ID. The Data Grid 2 then uses an XPath constraint through the association to only show items that match those IDs.

 

With this setup, nothing is left behind in the database because the data is cleared every time the page is entered. The only thing to be aware of is that if the same user opens the page in multiple browser tabs, the filter data could interfere with itself. If that’s a real concern, you can extend FilterSession with a simple page-specific identifier so each tab keeps its own separate filter state.

answered