Closed MiteshJ-Hub closed 2 years ago
remove your global currentGroupType
variable, such context-less variable are usually a very bad idea
also remove the beforeAddRule
listener, as you experienced it the list of filters should not be directly modified (the change-filter
plugin does it in a controlled way)
add a custom data to your group
$builderEl.queryBuilder('addGroup', $builderEl.queryBuilder('getModel'), false, { key });
getRuleFilters
filter event$builderEl.on('getRuleFilters.queryBuilder.filter', (e, filters, rule) => {
e.value = filters.filter(f => f.group === rule.parent.data.key);
});
getGroupTemplate
you should alter itCheck how it is done here https://github.com/mistic100/jQuery-QueryBuilder/blob/dev/src/plugins/not-group/plugin.js#L34-L42
Didn't added that kind of custom logic in the codepen to make it clear for you.
I hope more request are like this, thank you very much.
Hi,
We were trying to use jQuery Query Builder for multiple predefined group types.
You can see in this https://codepen.io/eonian_mitesh/pen/mdBRxOX?editors=0010 how we have started.
You will see in the above codepen sample that we have a common list of filters with a custom 'group' property. When you click on Add group, it will ask which type of group you want to add. When you will try to add a rule for any group, it will show all the filters in the filter dropdown box as I haven't added any special logic to filter/refine the filters list.
What we want is, if add a group of type e.g. RISK then it should show only 3 filter items having 'group' property value to be 'RISK' and same for other group type.
FYI - I have tried refining the querybuilder.filters list in the event called 'beforeAddRule' and it was showing a refined list but looks like it is also changing the component's model itself and was getting issues. Didn't added that kind of custom logic in the codepen to make it clear for you.
Any help would be appreciable.
Thanks, Mitesh J