Hi everybody,
I think this might be useful for development. The task is the following: how can I dynamically change the options of a dynamic filter based on another quick filter (or another parameter)? For example, on a certain page I have a dropdown parameter "City", and a quick filter for Owner that should respect the selected city. If no city is selected, the quick filter should display all records
Here is an example:
What needs to be achieved: if a city is selected in the City dropdown, then the Owner quick filter should display only those contacts whose city matches the selected value. If no city is selected, the quick filter should show all contacts
The code:
This calls crt.LoadDataRequest for the quick filter after the "City" value had changed.
{ request: "crt.HandleViewModelAttributeChangeRequest", handler: async (request, next) => { if (request.attributeName === "ContactDS_City_zsoqmn6") { await request.$context.executeRequest({ type: "crt.LoadDataRequest", $context: request.$context, config: { loadType: "reload", useLastLoadParameters: true }, dataSourceName: "OwnerQuickFilter_ComboBox_List_DS" }); } } }
And this reloads quick filter dataset depending on the current conditions (in our case includes owner filtration by the owner's city):
{ request: "crt.LoadDataRequest", handler: async (request, next) => { if (request.dataSourceName === "OwnerQuickFilter_ComboBox_List_DS") { const filter = new sdk.FilterGroup(); const selectedCity = await request.$context.ContactDS_City_zsoqmn6; if (selectedCity) { await filter.addSchemaColumnFilterWithParameter( sdk.ComparisonType.Equal, "City", selectedCity.value ); } else { await filter.addSchemaColumnIsNotNullFilter("Id"); } const newFilter = Object.assign({}, filter); newFilter.items = filter.items; if (!request.parameters) { request.parameters = []; } request.parameters.push({ type: "filter", value: newFilter }); } return await next?.handle(request); } }
The result:
a) Some City was selected:
b) Nothing was selected
