matfish2 / vue-tables-2

Vue.js 2 grid components
https://matanya.gitbook.io/vue-tables-2/
GNU General Public License v3.0
1.53k stars 305 forks source link

$or - Filter in initFilters #476

Closed molerat619 closed 6 years ago

molerat619 commented 6 years ago

I have following code, but it is missing the fact, that either the start_date or the end_date has to be in the given time period.

initFilters: {
    active: true,
    start_date: {start: moment().startOf('month'), end: moment().endOf('month')},
    end_date: {start: moment().startOf('month'), end: moment().endOf('month')},
}

Do I have to write a custom filter for that or is there something in place already?

matfish2 commented 6 years ago

A date range picker is by definition used to selected a date between two dates, i.e the date must be later than or equals to the start date AND earlier than or equal to the end date. If you have your own logic you can implement your own filter (see the docs on custom filters)

molerat619 commented 6 years ago

Now I have another scenario where this feature would be helpful and it has nothing to do with dates.

I want to filter by car, bus, both or none. Therefore I have created my own filter and it works for all cases except "filter by both".

What's the best way to put an or-query here?

image

matfish2 commented 6 years ago

define a vehicles array on your instance. Keep it up-to-date with the user's selection, and pass the array to the event as the query. Then check if the vehicle in contained in the passed array (query.includes(row.vehicle))

molerat619 commented 6 years ago

I got that far but now the question is how I can use it in the backend. I am using the EloquentClass but I don't see how that can handle "or"s. I know this module does not really support the EloquentClass, but I think it will be useful for others too who come across this need.

matfish2 commented 6 years ago

I thought you were asking about the client table. The Eloquent class is merely a barebones starter template. You can modify it to your needs, and if you think your changes will benefit others, you are welcome to send a PR. Anyway, it should be quite easy to implment. Instead of LIKE use WHERE IN and you are all set.

molerat619 commented 6 years ago

Alright, I'll see what I can do then. Thank you @matfish2