Using Jquery Datatables with inputs and selects as shown here: http://datatables.net/examples/api/form.html or if I used a custom column render handler to produce the input and selects how can I make the global table search work?
If you view the example you'll notice that only the first column, the read only one, is included in the search, what can I do to include the other columns in the search?
If you view the example in the link in my question and type "Tokyo" into the search all rows are returned. This is because "Tokyo" is an option in all dropdowns. I would want only rows with Tokyo selected to show. If you type in "33" you see no rows even though the first row has a value of "33" in the first column.
I can't seem to find any documentation on how to define what the search value is for a particular cell in a datatable.
Replace you input by Textarea, and add the css below. It will make your textarea looks like an input.
It is not very well documented. And it seems to work differently, or not work at all, between (sub)versions. I think dataTables is intended to automatically detect HTML-columns, but for some reason, most of the times, it doesnt. The safest way is to create your own search-filter :
This will return 33 on
<input>
's with value 33, and Tokyo on<select>
's where Tokyo is selected. Then define the desired columns as of typehtml-input
;see demo based on http://datatables.net/examples/api/form.html -> http://jsfiddle.net/a3o3yqkw/
Regarding live data: The issue is, that the type based filter only is called once. dataTables then caches the returned values so it not need to "calculate" all the values over and over. Luckily, dataTables 1.10.x has a built-in function for
cells
,rows
andpages
calledinvalidate
that forces dataTables to reset the cache for the selected items.However, when dealing with
<input>
's there is also the problem, that editing the value not is changing thevalue
attribute itself. So even if you callinvalidate()
, you will still end up in filtering on the old "hardcoded" value.But I have found a solution for this. Force the
<input>
'svalue
attribute to be changed with the<input>
's current value (the new value) and then callinvalidate
:For textareas use
text()
instead :This is also the case when dealing with
<select>
's. You will need to update theselected
attribute for the relevant<option>
's and theninvalidate()
the cell as well :forked fiddle -> http://jsfiddle.net/s2gbafuz/ Try change content of the inputs and/or the dropdowns, and search for the new values ...
This should search the entire table instead of specific column(s).
Best thing to do here is just update the cell container to the new value from the input and keep the datatable data object sync with the UI input: