How to overcome Freedom UI Quick Filter limitations and apply a custom programmatic filter to a DataGrid?
Hi everyone,
I am working on a Creatio Freedom UI page (8.3.x) where I have a DataGrid displaying records related to the current record. I need to provide users with a custom filter button that applies an additional filter to the grid programmatically.
Requirement
I have a lookup field, let's call it "Category", on the records displayed in the grid.
The requirement is:
- The grid already has the standard Freedom UI filters / Quick Filters.
- I want to add a custom button outside the grid.
- When the user clicks the button, I want to apply a specific Category value to the grid.
- The value may come dynamically from another field/page parameter, although for testing I am currently using a hardcoded GUID.
- The custom filter should work together with the existing grid filters, rather than replacing them.
- The grid should refresh automatically after applying the filter.
I created a custom request handler for the button:
{
request: "ApplyGridFiltersRequest",
handler: async (request, next) => {
const categoryId =
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
console.log("Category:", categoryId);
await request.$context.executeRequest({
type: "crt.LoadDataRequest",
$context: request.$context,
dataSourceName: "MyGridDataSource"
});
return await next?.handle(request);
}
}
This successfully triggers the grid reload.
I can also confirm that the crt.LoadDataRequest is being triggered and that the custom value is available.
However, I haven't found the correct way to inject the filter into the grid's existing filter collection.
- Apply a filter programmatically to a specific DataGrid datasource?
- Preserve the filters already applied by the user?
- Add my custom filter as an additional condition?
- Trigger the grid reload after applying it?
- Ideally remove/change the custom filter later without affecting the user's other filters?
Is there a supported request/API for manipulating the DataGrid's filter collection, or is the recommended approach to use a ViewModel attribute/page parameter bound to the grid filter?
I would prefer a supported Freedom UI approach rather than directly manipulating the DOM or relying on internal/private APIs.
Any examples using crt.*Request handlers would be greatly appreciated.
Thanks!
Like
Overriding the crt.LoadDataRequest and adding an additional filter (if some boolean attribute is set to true, which your button clicking should toggle) is probably your best bet. Instructions on adding a filter to the LoadDataRequest can be found here: https://customerfx.com/article/dynamically-filtering-a-lookup-on-a-creatio-freedom-ui-page/
Note: this will work if and only if the filter never needs to be applied on initial loading of the page, as Creatio bypasses the LoadDataRequest when loading in the first page of results for a list. It's quite annoying and the workarounds are quite messy. But it sounds like it should work for your purposes if you only want to apply the filter after clicking a button.