I'm using datatable 1.10.15
with server side processing. I want to set value for a column search when table initializes.
I tried this but without success:
$('#dataTable').DataTable({
...
columns:[
....
{name:'name', search:{value:'q'}}
....
]
});
You can try:
$('#example').dataTable( {
"search": {
"search": "Fred"
}
});
It will initialize the datatable with Fred
in search column.
Working Fiddle
Reference
Here can be used SearchCols
.
Basically the same as the search option, but in this case for individual columns, rather than the global filter, this option defined the filtering to apply to the table during initialisation.
The array must be of the same size as the number of columns, and each element be an object with the parameters search and escapeRegex (the latter is optional). 'null' is also accepted and the default will be used.
Example:
$('#example').dataTable( {
"searchCols": [
null,
{ "search": "My filter" },
null,
{ "search": "^[0-9]", "escapeRegex": false }
]
} );
This is the only right solution when you can set a default search value when initializing a datatable. it's worth the datatable documentation.
More info: https://datatables.net/reference/option/searchCols
Working example: http://live.datatables.net/piqidoqo/603/edit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With