How can we add a dynamic detail filter to a FreedomUI Page?
Hi Community,
We are trying to create a filter for this detail, that will use two conditions (one for each column) and a logical operator of “OR”. So basically, we only want the records that have the main record id on one of these columns (Contrato or Contrato Umbrella).
To achieve this, we first tried to add the filter using the FreedomUI Page Designer. However, the filter does not work with the logical operator “OR”.
So we needed to add it manually, through code. By following this post https://community.creatio.com/questions/detail-filter-freedom-ui. But that didn’t work.
An alternative was to add the filter in the viewModelConfigDiff section, but we don’t know how can we make the value dynamic.
Could you please help us find a solution to this problem?
Thank you.
Like
Hello Pedro,
Please review one of the community questions to find the example of Terrasoft.LogicalOperatorType.OR usage.
Additionally here is an explanation of how filtration on Detail work for FreedomUI.
Case description:
On Contacts page there is a Job experience detail with listed companies where the person worked. Our goal is to show only those departments in the department field that are specified for chosen employer (Account object). So, for this case, Alpha Business has only 2 departments listed in the Departments detail. We only want to see those 2 departments when choosing a department for this account on Job experience detail on Contact page.
For filtering we basically need just 2 base handlers to be triggered:
crt.DataGridActivateRowBusinessRulesRequest
– triggered when we click on an existing detail row or add a new one.crt.HandleViewModelAttributeChangeRequest
– triggered when we change a value of fields.
We also need to create our own handler which we can name usr.ApplyDepartmentFilter
. This one would find the currently active row of our detail to have access to its manipulations. After that, we check if account field is filled in and if yes, we create a filter for the Department field. To apply it, we need to use setValue
method by targeting filterAttributeName
that can be created using the formula: "{detailName}DS_{targetFieldName}_List_BusinessRule_Filter"
.
After that, it is important to use markAsPristine
method to make sure that the attribute is applied silently, without forcing us to save the row.
As for crt.DataGridActivateRowBusinessRulesRequest
, here we just need to filter it by request.dataGridViewElementName === "CareerList"
to target only the detail needed and then call the execution of usr.ApplyDepartmentFilter
request that was added earlier.
In crt.HandleViewModelAttributeChangeRequest
handler we need to cover the situation when the Employer (Account) field is changed to update the filtration for Department field. First of all, we check if request.attributeName === "CareerList"
. After that we select the active row and get control over Account field. We check if it’s changed by using account?.dirty
property and also if it has value with account?.value?.value
, because we would want to filter Department field only in case the Employer is filled in. If those 2 conditions are met, we use markAsPristine
method for the account field attribute. We use this one here because it will allow us to handle the subsequent changes of the Employer field. Without it, the field will remain dirty until we save the row. Eventually, we need to set value of the Department field to null using: row?.getAttributeControl(attributeName + "DS_Department").setValue(null, {silent: true});
After that, the usr.ApplyDepartmentFilter
handler can be executed to apply the filtration of Department field by Employer.