Warm tip: This article is reproduced from stackoverflow.com, please click
javascript crossfilter

Get all filtered values in crossfilter

发布于 2020-03-29 21:02:23

I have this cf:

const paymentsCf = crossfilter([
  {id: 1, quantity: 2, total: 190, tip: 100, type: "tab"},
  {id: 2, quantity: 2, total: 190, tip: 100, type: "tab"},
  {id: 3, quantity: 1, total: 300, tip: 200, type: "visa"}
]);

and I'm creating a dimension by ID and filtering it like this:

const dimension = paymentsCf.dimension(({ id }) => id);
dimension.filter(2);

If I do console.log(paymentsCf.groupAll().value()) fair enough I see 1.

But how can I access the whole filtered object to get the quantity, total, tip and type?

I know I can do feedbackCf.all() but that shows me all the 3 objects. Not only the filtered one.

Thanks!

Questioner
Mati Tucci
Viewed
43
aviya.developer 2020-01-31 19:11

You just need to add the top() method to expose the result:

const dimension = paymentsCf.dimension(({ id }) => id);
const res = dimension.filter(2);
res.top(1);

output:

[ { id: 2, quantity: 2, total: 190, tip: 100, type: 'tab' } ]