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

Numeric column by range #240

Closed
klevison opened this issue Jul 17, 2019 · 7 comments · Fixed by #252
Closed

Numeric column by range #240

klevison opened this issue Jul 17, 2019 · 7 comments · Fixed by #252

Comments

@klevison
Copy link

klevison commented Jul 17, 2019

Hi, is there a way to filter a numeric column by range?

For example:

Tasks with duration between 30 and 60.

@ghiscoding
Copy link
Owner

I think you could do that with the slider filter, there's a minValue and a maxValue, there's also a sliderStartValue but I don't think you would need this one.

So you could try with

{
  id: 'duration',
  name: 'Duration (days)',
  field: 'duration',
  filterable: true,
  type: FieldType.number,
  filter: { 
    model: Filters.slider, 
    minValue: 30,
    maxValue: 60,
    params: { sliderStartValue: 45 }, // this property is specific to the slider filter, so it must be defined in params
  },
}

if that is not what you want, there's also the possibility of creating your own custom filter

@klevison
Copy link
Author

Sliders will set only one value a need an interval. Imagine that I'll need a interval of dates? Or interval of numeric numbers. I need to set two args dynamically.

@ghiscoding
Copy link
Owner

if that is not what you want, there's also the possibility of creating your own custom filter

@ghiscoding
Copy link
Owner

ghiscoding commented Jul 17, 2019

Last possibility, if you don`t want to create your own filter, would be to duplicate the column in the grid with 2 different filters (1 for the min value and another for the max value). It's not exactly the best but it's certainly the easiest way to implement.

Imagine that I'll need a interval of dates?

For that you can use Flatpickr option for date range. You can pass any of the Flatpickr option(s) to the filter filterOptions of your filter. Actually that won't work, the FilterService expect only 1 value, that would require some changes to the Service for this to work

... so with all of that, I still think the easiest, and doable now, would be to duplicate the column

@ghiscoding
Copy link
Owner

I had a quick play at it, I think it's doable but I would have to update every Filter Conditions to support this. I basically use the ".." to represent a range (e.g. "5..10") and I modified the numberFilterCondition to handle this check, if it finds the ".." it does 2 conditions instead of a 1 which are (condition1 is >=5 and condition2 is <=10) and that seems to work out nicely. The result is shown in the print screen below. I also added 2 new operator, the default is RangeInclusive (>=5 and <=10) and also RangeNotInclusive (>5 and <10).

I'd be interested in feedback if that works out for you. I'm not sure that I could do that for every filters though, for example Flatpickr shows a date range as "2019-01-01 to 2019-01-31", I might have to do extra work to parse that out. Anyhow, on an input filter, that would be easy to implement as I've done a quick one with input of numbers as shown below

image

@ghiscoding ghiscoding added wip and removed question labels Aug 7, 2019
ghiscoding added a commit that referenced this issue Aug 19, 2019
feat(filter): add filter search range functionality, closes issue #240
@ghiscoding
Copy link
Owner

closed by PR #252

@ghiscoding
Copy link
Owner

ghiscoding commented Aug 20, 2019

Range Filters are now released under the new version 2.10.1 and a new Example 25 was created to showcase this new feature

If you like the lib and you haven't already up vote, please do so.. ⭐️ 😸
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants