Reputation: 2245
How can I set the default text value for the input field for the columnfilter plugin for the datatables api?
$(document).ready(function () {
var t1 = $( '#test').dataTable({
}).columnFilter();
My table has several columns and I have tried setting the input box to have a default serach value as:
$("input:eq(6)").val("myDefaultValue");
But this just displays myDefultValue in the search box , but doe not apply the filter.
I also tried triggering change and keydown, but both fail.
I am testing in Chrome, any ideas?
Upvotes: 2
Views: 4357
Reputation: 2245
UPDATE: Following the idea from Msieur Toph to try to trigger the search event, I have found the solution (by looking at the columnfilter source code), which is to trigger the keyup event.
$("input:eq(6)").val("myDefaultVal").trigger('keyup');
Upvotes: 0
Reputation: 2676
Sorry for my first post. I red wrong the api doc.
See this page : http://datatables.net/reference/api/column().search()
You need to select the column and then use the search()
method.
$( '#test')
.columns(6) // to select the sixth column
.search('myDefaultValue')
.draw();
It should work better.
I delete my first post.
Upvotes: 3