dasDaniel / svelte-table

A svelte table implementation that allows sorting and filtering
https://dasdaniel.github.io/svelte-table/
MIT License
535 stars 40 forks source link

Added Range Filter functionality #102

Closed danraps closed 2 years ago

danraps commented 2 years ago

I've created the ability to have a two point range slider (c/o svelte-range-slider-pips) for columns. To use it, you can add the rangeValues key and filterOptions to 'range' for the specific column entries.

{
    key: e,
    title: e,
    value: (v) => v[e],
    sortable: true,
    headerClass: "text-left",
    rangeValues: {
        min: 0,
        max: 1000,
        step: 1,
        range: [0, 1000],
    },
    filterOptions: "range",
}
dasDaniel commented 2 years ago

I appreciate the PR, but I won't be adding this feature as-is at this time.

I would really like to keep this as a 0-dependency component and adding the svelte-range-slider-pips dependency would prevent that. It's licensed as MIT so you're more than welcome to fork this though if you need to for your needs.

As an aside, even though that dependency is bundled into the build outputs, using inside another svelte project would throw an error, since svelte-range-slider-pips is listed as a devDependency.

Could you implement with a component? I think the header filter cell could support passing a component and interact with the column filter similar to renderComponent.

danraps commented 2 years ago

I threw this together for a specific need I had at work and thought it might be useful for others, but you raise some very valid points!

When I get a bit of free time, I’ll rework it with the implementation you suggested, since that would allow for more use cases and be more consistent with the rest of your package anyway. Thanks for the recommendation!