Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering on value dimensions with string filter values instead of ints #45

Closed
turnerniles opened this issue Apr 11, 2017 · 3 comments
Closed

Comments

@turnerniles
Copy link
Collaborator

turnerniles commented Apr 11, 2017

When filtering on value fields, strings passed in as filters are not converted into ints. Should we do this in the pivot logic or on the front end? Numbers on the front-end are rendered as strings so when passed back as in a filter as a they do not match the respective int stored in the pivot.

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 pivot = new pivot(dataArray, ['age'], [], 'age', 'sum');

// returns original pivoted data because it is excluding a string that does match the int 8 in the pivot
pivot.filter("age", ["8"], 'exclude')

// works
pivot.filter("age", [8], 'exclude')
@turnerniles turnerniles changed the title Filtering on values fields Filtering on values dimensions Apr 11, 2017
@turnerniles turnerniles changed the title Filtering on values dimensions Filtering on value dimensions Apr 11, 2017
@turnerniles turnerniles changed the title Filtering on value dimensions Filtering on value dimensions with string filter values instead of ints Apr 11, 2017
@pat310
Copy link
Owner

pat310 commented Apr 14, 2017

@turnerniles
We could convert everything to strings and tell the user that everything will be converted to a string. But then the user would be limited with the fancy custom filtering when passing a callback function (I guess they could convert it back to whatever data type they want or we could just not change the data type if a callback is passed). It also feels weird to change the user's data type to a string for filtering but if they do some mathematical aggregations on that dimension (like averaging or maximum/minimum) then it should stay as a number? The more I think about it, the more complicated I think it actually is to manipulate the data type... Maybe we should just handle it on the front-end by using the callback feature for filtering?

@turnerniles
Copy link
Collaborator Author

turnerniles commented Apr 16, 2017

I agree in principle if you are writing code and using quick-pivot without a front-end. But when rendering it on the frontend and passing it back, the value passed back will be a string. And if I convert all strings to ints, before calling the filtering function, if the number is stored as a string on the backend then it won't work. Also if we use an <input> tag to allow the user to pass a custom value, it will also be passed back as a string.

I will use the custom callback for the UI.:
return filterValues.indexOf(value) == -1; instead of return filterValues.indexOf(value) === -1;

And we can close the issue. What do you think?

@pat310
Copy link
Owner

pat310 commented Apr 17, 2017

Sounds good!

@pat310 pat310 closed this as completed Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants