Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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');

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top