Datatable column filtering not working server side

I have already done server side processing in datatable. Now i want to make individual column filtering server side processing as well.

I have tried.

 $('#example thead th').each(function () {
     var title = $(this).text();
     $(this).html(title+' <input type="text" class="col-search-input" placeholder="Search ' + title + '" />');
});
var table = $('#example').DataTable({
        dom: 'lfBrtip',
        "processing":true,
        "serverSide":true,
        "ajax":{
            "url":"{{route('homeajax')}}",
            "dataType": "json",
            "type": "POST",
        },
        "columns":[
            {"data":"name"},
            {"data":"Position"},
            {"data":"office"},
            {"data":"age"},
            {"data":"start_date"},
            {"data":"salary"},
        ],
        initComplete: function(){
            this.api().columns().every(function(){
                $('input', this.header()).on('keyup change', function () {
                    if (table.search() !== this.value) {
                        table.search(this.value,true).draw();
                    }
                });
            });
        },
        paginate: true,   
    });

It works for only one column but when i try to search from another field it doesn't work.

It shows all the data when i try to input from another column,


It depends on server side query which you used for data fetching. If joins in your query then you need to pass column name like below code.

"columns":[
        {"data":"name"},
        {"data":"tbl.Position"}, //tbl is join table alias.
        {"data":"office"},
        {"data":"age"},
        {"data":"start_date"},
        {"data":"salary"},
    ],

But in a real time scenario when you are working with large data it is not feasible to filter, sort or page data at client side. Hence, this article shows user step by step how to use Data Table and apply server side filtering, sorting and paging using MVC and Entity Framework.


I know it disrupts your design a little but are you able to let DataTables create the search inputs? That way it can set the event listener to search only that column. I use a variation of the code from this link:

http://live.datatables.net/tobekuxu/1/edit

Another thing to look at (perhaps try this first) is I think you are searching the whole table when you want to be searching only that column. Try something like this inside your columns().every() function:

this.api().columns().every(function(){
    let column = this;
    $('input', this.header()).on('keyup change', function () {
        if (column.search() !== this.value) {
            column.search(this.value,true).draw();
        }
    });
});

Here we will see followings with ASP.NET MVC as server side Part 1: Implement jQuery Datatable (Basic initialization) in ASP.NET MVC application. Part 2: jQuery Datatable server side pagination and sorting in ASP.NET MVC; Part 3: Implement custom multicolumn server-side filtering in jQuery dataTables


May be this ajax code will help for you. aoColumns if you need to enable filter only name,Position and start_date(Custom filter)

 "aoColumns": [
        { "bSortable": true },
        { "bSortable": true },
        { "bSortable": false },
        { "bSortable": false },
        { "bSortable": true },
        { "bSortable": false }
    ]

The script used to perform the server-side processing for this table is shown below. Please note that this is just an example script using PHP. Server-side processing scripts can be written in any language, using the protocol described in the DataTables documentation.


There are many ways to get your data into DataTables, and if you are working with seriously large databases, you might want to consider using the server-side options that DataTables provides. With server-side processing enabled, all paging, searching, ordering actions that DataTables performs are handed off to a server where an SQL engine (or


JQuery-Datatables-server-side-with-individual-column-searching-on-specific-columns-only server side individual column filtering using this example with little


Column Search with DataTable Server Side Processing Output. This output screenshot shows the dynamically fetched results by using DataTables Server-side scripts. In this output, the column-wise search option is shown to filter the column data by keyword. View Demo Download