How to set the default text value of a columnfilter for the datatables jquery api

StackOverflow https://stackoverflow.com/questions/23636753

  •  21-07-2023
  •  | 
  •  

سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top