GriddleGriddle / Griddle

Simple Grid Component written in React
http://griddlegriddle.github.io/Griddle/
MIT License
2.5k stars 378 forks source link

Advanced Filtering #746

Closed benoj closed 6 years ago

benoj commented 7 years ago

Hey,

Like the project, jut wondering if it is possible to do more advanced filtering across multiple fields e.g. say with row data { name: "Bob", age: 20, categories: ["male","young"] }, { name: "Alice", age: 49: categories: ["female", "middle-age"]

Would it be possible to search by:

a) age between x and y b) which categories a person is in c) text search on name

From docs it looks like its just text across all of the properties? Are the more advanced searches that I am talking about possible?

Thanks,

Ben

dahlbyk commented 7 years ago

Nothing about the component implementation requires that filter be limited to a simple string, but that's how Filter and LocalPlugin are currently implemented.

Customizing the former to setFilter with a complex filter object should be relatively straightforward. Customizing the latter is currently pretty tedious, short of cloning LocalPlugin, but https://github.com/GriddleGriddle/Griddle/pull/743 should improve that situation. It also seems reasonable that we could update LocalPlugin to be a lot smarter about filtering out of the box, e.g.:

setFilter({
  age: a => (x <= a && a <= y),
  categories: [cat1, cat2],
  name: nameSubstring
})

In other words, if filter is an object we would treat its keys as the column ids to be filtered, with either string values, an array of values to match, or a predicate to apply to the value. Would be glad to help if anyone's interested in taking a crack at this.

benoj commented 7 years ago

I need this functionality for what I'm doing so will make a PR against this hopefully in the next few days.

Cheers,

Ben

aaronsmulktis commented 3 years ago

This was exactly what I needed as well. Thank you @benoj for hooking this up.