pat310 / quick-pivot

Quickly format data to create a pivot table
https://www.npmjs.com/package/quick-pivot
MIT License
63 stars 21 forks source link

Filtering out all values returns empty array. Should return remaining unfiltered fields with 0 values. #60

Open turnerniles opened 7 years ago

turnerniles commented 7 years ago

Filtering out all values returns empty array. Should return remaining unfiltered fields with 0 values.

const dataArray = [ ['name', 'gender', 'house', 'age'], ['Jon', 'm', 'Stark', 14], ['Arya', 'f', 'Stark', 10], ['Cersei', 'f', 'Baratheon', 38], ['Tywin', 'm', 'Lannister', 67], ['Tyrion', 'm', 'Lannister', 34], ['Joffrey', 'm', 'Baratheon', 18], ['Bran', 'm', 'Stark', 8], ['Jaime', 'm', 'Lannister', 32], ['Sansa', 'f', 'Stark', 12] ];

const testPivot = new pivot(dataArray, ['house', 'gender'], [], 'age', 'sum', '');

testPivot.filter('gender', ['f','m'], 'exclude')

testPivot.data.table returns []

Instead it should return "[{"value":["",""],"depth":0,"type":"colHeader","row":0},{"value":["Baratheon",0],"type":"data","depth":0,"row":1},{"value":["Lannister",0],"type":"data","depth":0,"row":2},{"value":["Stark",0],"type":"data","depth":0,"row":3}]"

Or if this is a tremendous amount of work perhaps just the empty header.