Reputation: 166
I'm trying to set an initial/default value for the filter input in a DataTable. Doing it with jquery on document ready causes the filter to perform a search for the value. I've searched through the DataTables documentation but can't find anything that references this.
Upvotes: 2
Views: 9500
Reputation: 21
You can set oSearch at datatable initialization
$(document).ready( function() {
$('#example').dataTable( {
"oSearch": {"sSearch": "Initial search"}
} );
} )
Documentation: http://legacy.datatables.net/ref
Upvotes: 2
Reputation: 107
In my case for DataTables 1.10.x a little mod for package answer:
"fnInitComplete": function(oSettings, json) {
$("input[aria-controls="+oSettings.sTableId+"]").val("val");
}
Upvotes: 1
Reputation: 4801
Use fnInitComplete
parameter on table initialization:
$("#table").dataTable({
"fnInitComplete": function(oSettings, json) {
$("#" + oSettings.sTableId+"_filter input").val("value");
}
});
Upvotes: 4