Apply a filter to a datagrid by code (Freedom UI)
Hi,
There is an issue with apply a filter to a datagrid by code (Freedom UI).
We have a page parameter (ex: UsrDuns), and we want to filter an account datagrid filtered by this text value.
When done on crt.HandleViewModelInitRequest handler, no filter is applied, so all accounts are loaded.
When done by manually changing a TextField and use this text field to apply the filter, the filter works as expected.
Is there any way to apply this filter on page load (like in the old UI) ?
Best regards,
Like
Hello,
Can you share an example of the implemented code? Screenshots with an example page would also be helpful.
On page Load, 2 is not filtered by 1
handlers: /**SCHEMA_HANDLERS*/[ { request: "crt.HandleViewModelInitRequest", handler: async (request, next) => { await next?.handle(request); request.$context.events$.subscribe((async (evt) => { if (evt?.type === "finish-load-model-attributes" && evt?.payload?.PageParameters_UsrTextParameter1_p75os8h) { var siren = await request.$context[ clientTool.findPageParameterByDesignName(request, "UsrNumeroSIREN") ]; await clientTool.reloadGridDetail(request, "DataGrid_yoo8q38DS"); } })); } }, { request: "crt.LoadDataRequest", handler: async (request, next) => { console.log("LoadDataRequest - START"); if(request.dataSourceName === "DataGrid_yoo8q38DS") { console.log("LoadDataRequest - DS"); var siren = await request.$context[ clientTool.findPageParameterByDesignName(request, "UsrNumeroSIREN") ]; if (siren) { console.log("LoadDataRequest - SIREN=" + siren); if (typeof request.parameters === "undefined") { console.log("Init request.parameters"); request.parameters = []; // Initialize it as an empty object or some default value } if(request.parameters) { const filter = new sdk.FilterGroup(); await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "UsrNumSiren", siren); // note, these lines are only needed due to an issue with filters in Creatio-DevKit SDK // expected to be fixed in Creatio 8.1 const newFilter = Object.assign({}, filter); newFilter.items = filter.items; request.parameters.push({ type: "filter", value: newFilter }); } } } return await next?.handle(request); } }, { request: "crt.HandleViewModelAttributeChangeRequest", handler: async (request, next) => { if(request.attributeName === clientTool.findPageParameterByDesignName(request, "UsrNumeroSIREN")) { console.log("HandleViewModelAttributeChangeRequest"); await clientTool.reloadGridDetail(request, "DataGrid_yoo8q38DS"); } return next?.handle(request); } } ]/**SCHEMA_HANDLERS*/,
Jerome BERGES,
Hello,
And what is the clientTool? And if it's not working when changing the attribute have you tried adding the search icon button near the parameter field and perform the search as in the regular search component by clicking the search icon?
Oleg Drobina,
clientTool is just an utility module and the findPageParameterByDesignName method is just a way to retrieve the parameter attribute name by it's technical design name (Usr....).
I fix this issue by using the old Terrasoft.createFilterGroup in HandleViewModelAttributeChangeRequest, then a serialize in the PredfinedFilter attribute
{ request: "crt.HandleViewModelAttributeChangeRequest", handler: async (request, next) => { if(request.attributeName === clientTool.findPageParameterByDesignName(request, "UsrNumeroSIREN")) { console.log("HandleViewModelAttributeChangeRequest - UsrNumeroSIREN"); var siren = await request.$context[ clientTool.findPageParameterByDesignName(request, "UsrNumeroSIREN") ]; // > Old Syntax const filterGroup = Terrasoft.createFilterGroup(); filterGroup.add("sirenFilter", Terrasoft.createColumnFilterWithParameter( Terrasoft.ComparisonType.EQUAL, "UsrNumSiren", siren) ); // > Données annuelles request.$context.DataGrid_yoo8q38_PredefinedFilter = filterGroup.serialize(); // > Données Trimestrielle request.$context.DataGrid_zigtth6_PredefinedFilter = filterGroup.serialize(); // > Données mensuelles request.$context.DataGrid_q8okf77_PredefinedFilter = filterGroup.serialize(); } return next?.handle(request); } }