Seungwoo321 / vue-pivottable

It is a Vue port of the jQuery-based PivotTable.js
MIT License
136 stars 72 forks source link

Allow valueFilter to filter-in and filter-out without listing all values. Like an include and exclude. #77

Closed raisercostin closed 5 months ago

raisercostin commented 8 months ago

Allow configuration of valueFilter without listing all values for a key. All false will exclude all. Then add the needed one with true. All could also be selected, and exclude the unwanted ones with false. Is also compatible with existing clients.

     Sample:
      ```
      valueFilter: {
        category: {
          all: false,
          'field1': true,
          'field2': false
        }
      }
Seungwoo321 commented 8 months ago

I tested it in the example project and it doesn't work. I think this is because the default value is falsely when the item is selected. The item you want to exclude must have the value true.

But try changing false to true in the following code:

         if (valueFilterItem && Object.keys(valueFilterItem).length) {
           // add all keys to be filtered out
           if (valueFilterItem.all) { // <-------------------------- here --------------------------
             Object.keys(values).forEach(k => {
               if (k !== 'all') {
                 const keyPresent = valueFilterItem[k]
.
.
.

And I confirmed that if all is true, all values are excluded by default.

       valueFilter: {
         date: {
           all: true
         }
       },

If I misunderstand, please provide sample code. Please understand that there is no test code.

Thank you for your interest in this project

raisercostin commented 8 months ago

Yes. You're right. I changed the meaning. valueFilter meaning is to filter out. I will change to be compatible with existing behavior.

raisercostin commented 8 months ago

Fixed. I also changed the 'all' field to '*'. Could be configurable but I didn't want to add complexity.