"not like" search
"not like" search
Has anybody created "not like" search capability that works like the regular DataTables search box, where it searches all fields? I know I can add a custom text box and send the contents and use them in the ajax call like a parameter, but the where statement would have to have each field in it. I like how the built in searchbox looks at each field and would want something like that if possible. I'm thinking I can't be the first person to want this
This question has an accepted answers - jump to answer
Answers
Are you using server side processing?
If using client side processing then take a look at using a Search Plugin.
Kevin
For client side processing Kevin's advise is the best using $.fn.dataTable.ext.search.push which works great.
If you want to do server side searching in a proprietary manner using the where clause you can either use each field in the WHERE clause or you use what I've called a global search field.
In my case the "global search field" contains:
- language specifically rendered database content (e.g. if your database date is 2020-07-08 00:00:00 and the user enters 8.7.2020 or 08/07/2020 nothing is going to be found without rendering!)
- all of the contents of parsed documents the user uploaded before and / or that were made machine readable in a different step (i.e. pdf's, MSOffice etc. documents)
All of this is done using SQL views. In more complex cases it is even a hierarchy of views.
So this nice little view anticipates the user's search entries in German or English. The view renders the database content in various formats the user may enter at the front end if her language is either German or UK English. American date formats etc are not supported.
The next step is then to create a second view that is based on this view and other information in order to create the "global search field". If you are still interested in seeing this and the respective Editor code let me know ...
This terribly looking line is my favorite
It renders a database amount 1000000.99 as 1.000.000,99.
To render that amount the English way the statement is much easier. This one renders the same database amount as 1,000,000.99
I think I am going to go with the client side search extension. The example given in the documentation seems pretty straight forward. But since I am wanting to search all fields, I guess I would use something like data.includes(searchValue)
one thing I don't understand looking at the example; I have multiple data tables on one page. I want this search to only work on one of the datatables. How do I do this?
See if this thread helps.
Kevin
... or even easier: If your data tables on the same page have "row" variables that are unique to them you can check for them being "undefined" and hence make sure the search only applies to the one data table that you want. I use it that way but you can also apply different searches to each data table with this trick like in here (old code, could be done better - but it works ...).
This thread may be helpful as well ... I had similar issues with this:
https://datatables.net/forums/discussion/60000
rf, I think I get what you are doing there. unfortunately, my datasets look very identical to each other. You may recall my projects are MVC .net. In my controller, the data comes back like this:
"Table" seems to be the default for the data being returned:
If I can change them from "Table" to something more uniquely identifiable, then I believe I can use your code. but not sure how to assign the "name" that the data is being returned with to other than "Table".
The thread I linked to checks the table ID in the search plugin. Here is an example I created for another thread:
http://live.datatables.net/tihuyiqi/1/edit
Kevin
ahhh, nice. I will give that a try. thanks.
We're about to release another extension fairly soon (probably later this month), that will have that 'not' search built-in - it's called SearchBuilder. It's not released yet, we're still tweaking it, but this here will give you a good idea of what it can do.
Colin
@Colin - great idea. Now, if only it were applicable to individual column filters, joy would be unconfined...
Ok. I am almost there. However, I realize that the array.includes() function as well as .filter() and .some() are looking for complete values. I am needing to see where a value of ANY field is LIKE something. I guess for now I will hard code the field names and use string.includes() which seems to do partial text matching
You should be able to loop through the
searchData
parameter. Its an array of the column data for the row.Kevin
this seems to have done the trick:
i further refined it so the user can enter multiple words separated by a space, just like the built in search box.
Good job, it looks good!
Kevin
and just one more change to make it easier to add other dataTables on the same page: