0

Is it possible to use a NOT LIKE conditional when filtering DataTable?

The DataTable is not populated via an ajax call, it is just populated from a simple query looped over in the page.

I want to be able to enter something like this: "W-2%" in the search box and only show items that do not start with "W-2".

So basically I am doing this: where name NOT LIKE 'W-2%'

DataTable Js

    $('#inventoryLocationTable').DataTable( {
        "iDisplayLength": 20,
        "order": [[ 1, "asc" ]],
        "aLengthMenu": [[10, 25, 50, 100, 500, 1000], ["10 Per Page", "25 Per Page", "50 Per Page", "100 Per Page", "500 Per Page", "1000 Per Page"]]
    });

Is this possible? Thanks.

1

1 Answer 1

3

You could use fnFilter as described in https://datatables.net/api or also you could build you own custom filter (explained in http://datatables.net/development/filtering)

If you need to match all results except the ones starting with W-2, maybe you could only use fnFilter and build a regex.

In this case it would be:

$('#inventoryLocationTable').dataTable().fnFilter("^(.(?!W-2))*$", null, true, false);

I build a jsFiddle to test it, it forces the filter after loading the table (check that rows containing W-2% doesn't appear).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.