Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I search in a specific column using the jQuery DataTables plugin?

I used the jquery dataTable plugin to show a table which contains (username, dates, and email). I want to disable the filtering/search for the username and email columns and enable just the search for the dates. when I click on the search field I'll open a calendar to choose the date which we will look for.

I just want to use this plugin for filtering only dates, basically. Can this be done?

-edit--

I read the docs :dateRange But It doesn't work for me I added the

('.dataTable').dataTable()
    .columnFilter({
        sPlaceHolder: "head:before",
        aoColumns: [null, { type: "date-range" }, null]
    });

And I duplicated the headers but I can't get the date fields or any other field to search the data into.

like image 783
Dev DOS Avatar asked Sep 16 '25 06:09

Dev DOS


2 Answers

You can use column().search() to obtain search on specific value, ex:

  var table = $('#example-table').DataTable();

  $('#search-input').on('change', function(){

    table
    .column(4)
    .search(this.value)
    .draw();

  });

Working Demo

Refrences

like image 79
Walid Ammar Avatar answered Sep 17 '25 21:09

Walid Ammar


There are multiple ways of doing this and one of them is mentioned follow which i personally felt is the easiest one, with the following you define which columns NOT TO LOOK FOR while searching using datatable search.

$('#example').dataTable( {
'columnDefs' : [
        { 
           'searchable'    : false, 
           'targets'       : [0,2,3] 
        },
    ]
} );
like image 36
Hassan Qasim Avatar answered Sep 17 '25 21:09

Hassan Qasim