vincjo / datatables

A toolkit for creating datatable components with Svelte
https://vincjo.fr/datatables
MIT License
363 stars 15 forks source link

Inverse Filter #70

Closed Smith-Chris1 closed 9 months ago

Smith-Chris1 commented 9 months ago

Ok - time for another dumb question.

Lets say I have defined a filter, using contains BUT what if I want the inverse of that, something like notContains or !contains.

I'm sure its possible, but I can't seem to figure out how to do that.

vincjo commented 9 months ago

Thx for your question

There's a possibility, indeed. You can create a custom check function like this:

const customCheck = (entry, value) => {
    entry.indexOf(value) === -1
} 
// Then pass it to the filter method as an argument:
handler.filter('value', 'columnName', customCheck)

But I'm going to add this inverse filter natively. contains will become isLike + will add isNotLike

I remain open to all suggestions if idiomatic comparators like this are missing. I keep you in touch.

Smith-Chris1 commented 9 months ago

As always, you're the best!

Smith-Chris1 commented 9 months ago

For now - I've added this:

Comparator.d.ts:check

isNot: (entry: any, value: any) => boolean;

Comparator.js:check

isNot: (entry, value) => { return entry.indexOf(value) === -1 },

I know I can do a custom one, but in an effort to look smart and keep similar functions together, that's what I've done.

vincjo commented 9 months ago

Yes I understand. Glad you found the location in the source code btw.

For my part I've just published isNotLike in 1.12.7

So you'll find isNotLike and isNotEqualTo in addition. Examples in the doc: https://vincjo.fr/datatables/advanced-filters/comparators

Note: contains has been deprecated only, and there's no plan to remove it