akveo / ng2-smart-table

Angular Smart Data Table component
https://akveo.github.io/ng2-smart-table/
MIT License
1.63k stars 878 forks source link

Filter 'andOperator' per Filter instead of globally #322

Open cgebe opened 7 years ago

cgebe commented 7 years ago

This is a feature request:

Adding Filters individually with a boolean operator, instead of having one boolean operator for connecting all filters.

Example:

Now all filters are applied either by the AND operator or OR operator, which means expressions like:

filter1 && filter 2 && filter 3 && filter 4
filter1 || filter 2 || filter 3 || filter 4

It would be great to be able to add filters individually with their preceding operator to the filter chain.

source.addFilter(filter1, false);
source.addFilter(filter2, true);
source.addFilter(filter3, false);
source.addFilter(filter4, true);

would result in the following filter chain: filter1 && filter2 || filter3 && filter4

igorxciv commented 7 years ago

Hello @cgebe !

I see that source object already supports this method: https://github.com/akveo/ng2-smart-table/blob/master/src/ng2-smart-table/lib/data-source/local/local.data-source.ts#L169

Does this method satisfy your goals?

cgebe commented 7 years ago

Its not possible to create a boolean expression like formulated above with this method. The addFilter method sets the andOperator for the filterConf object, which means for all filters currently added.

Adding n filters with andOperator = false means n filter are connected by OR. On top of that, you add one filter (n+1) with andOperator = true. Now the filterConf.andOperator attribute is set to true and all filters get connected by AND.

See protected filter(data: Array<any>): Array<any> https://github.com/akveo/ng2-smart-table/blob/master/src/ng2-smart-table/lib/data-source/local/local.data-source.ts#L236