Skip to content

Commit

Permalink
ValueFilter's keys with the special field '*' will match all values a…
Browse files Browse the repository at this point in the history
…nd filter them out (true) or show (false).

Sample:
```
valueFilter: {
  field1: {
    '*': true, // filter out all values
    'value1': true, // filter out value1
    'value2': false // select to display value2
  },
  field2: {
    '*': false, // select to display all values
    'value1': true, // filter out value1
    'value2': false // select to display value2
  }
}
```
  • Loading branch information
raisercostin committed Jan 12, 2024
1 parent 0c2e6fb commit f3fe6aa
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions src/PivottableUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ export default {
cols: [],
rows: [],
attributes: [],
/**
* ValueFilter's keys with the special field '*' will match all values and filter them out (true) or show (false).
Sample:
```
valueFilter: {
field1: {
'*': true, // filter out all values
'value1': true, // filter out value1
'value2': false // select to display value2
},
field2: {
'*': false, // select to display all values
'value1': true, // filter out value1
'value2': false // select to display value2
}
}
```
*/
valueFilter: {},
renderer: null
},
Expand Down Expand Up @@ -237,15 +255,29 @@ export default {
this.propsData.aggregatorName = this.aggregatorName
this.propsData.attributes = this.attributes.length > 0 ? this.attributes : Object.keys(this.attrValues)
this.unusedOrder = this.unusedAttrs
Object.keys(this.attrValues).forEach(key => {
let valueFilter = {}
const values = this.valueFilter && this.valueFilter[key]
if (values && Object.keys(values).length) {
valueFilter = this.valueFilter[key]
Object.entries(this.attrValues).forEach(([key, values]) => {
let attributes = {}
const valueFilterItem = this.valueFilter && this.valueFilter[key]
if (valueFilterItem && Object.keys(valueFilterItem).length) {
if (valueFilterItem.all === true) {
// add all keys to be filtered out
Object.keys(values).forEach(k => {
if (k !== 'all') {
const keyPresent = valueFilterItem[k]
if (keyPresent === undefined || keyPresent === true) {
attributes[k] = true
} else {
// attributes[k] = false
}
}
})
} else {
attributes = valueFilterItem
}
}
this.updateValueFilter({
attribute: key,
valueFilter
valueFilter: attributes
})
})
},
Expand Down

0 comments on commit f3fe6aa

Please sign in to comment.