mlin01
mlin01
mlin01
Posts: 5Questions: 1Answers: 0
- In datatable.js 2.1.8, the search function does not search anything.
- How to customize the search function for the built in search box? In my table, some TD has input[text] and select, I want to search the input only.
Thanks,
Michael
This question has an accepted answers - jump to answer
Answers
The search input works in this example. Please provide more information about your environment and why you think the search function doesn't work. Better is a test case replicating the issue.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
You may need to use
cell().invalidate()
to update the inputs. Here is an example:https://live.datatables.net/zukacehi/1/edit
Depending on your table data you might be able to use
/columns.searchable
to disable searching of columns with the select inputs.If you still need help then please provide a test case showing the inputs you want to search.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thanks for the reply. Below is my *.cshtml content and js code, the sorting is working, but search does not work.
and js function
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
Just upload the data table debugger, debugger code is: ubatof
Only the developer has access to the debugger output. It may or may not have the HTML table in the output. Possibly you can use the browser's view the source option and copy a few rows of the HTML table and your Datatables config into this template:
https://live.datatables.net/
Does the search work for the first two columns but not the third or does it not work at all?
Is the problem that the search doesn't work after updating the input?
Have you tried the code provided in my example to keep the input value and Datatables search cache updated with
cell().invalidate()
? Specifically this code:Kevin
This is what a row's HTML looks like:
The key thing here is that
input
andselect
in the first column.Live DOM elements do not get searched by DataTables. There might be a way through data invalidation, but it isn't something I've looked into I'm afraid.
Allan
Can someone point to me where in the code the search is executed?
The Datatables search functionality is quite complicated so showing you the code probably won't be very useful. But I believe if you search for the function
_fnFilter
in datatables.js you will see the core part of the code.I think the easiest option would be to separate the text input and select inputs into different columns. Then possibly the solution with
cell().invalidate()
I presented above would work..https://live.datatables.net/zukacehi/1/edit
Another option is to add a hidden column, using
columns.visible
, that contains the value of the text input. This can be searched while disabling search of the combined column usingcolumns.searchable
.A third option might be to use
search.fixed()
to extract the text input value of the combined column to compare with the search term. This might have some performance impacts since the DOM nodes will be accessed for each row each time the search is executed.If you want help with this please provide a simple test case with an example of a few rows of data. This way we can help with providing a running example that may work for you.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I had a few minutes to put together this simple example:
https://live.datatables.net/zukacehi/116/edit
It has a text input and select input in the same column. It uses
columns.render
for the combined column to get the text input to set Orthogonal data for thefilter
operation.Note also the need for the
change
event to update the Datatables data cache with the update text inputs.If you still need help then please update my test case or create your own with an example of your solution so we can provide more specific suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thank you, thank you all.