CK8
CK8

Reputation: 359

jQuery bootstrap datatable search and sort doesn't work

I got this code partial working. ajax code was able to fetch json data from server. But the search function and sort function doesn't work. Here is my js code. Please help!

$(document).ready(function(){
     $('.dataTables-example').DataTable({
            pageLength: 25,
            responsive: true,
            dom: '<"html5buttons"B>lTfgitp',
                "processing": true,
                "serverSide": true,
                "ajax"      : "getData3.php",
                "columns"   : [
                   { "data" : "id"},
                   { "data" : "sales_license"},
                   { "data" : "first_name" },
                   { "data" : "last_name" },
                   { "data" : "email"}
                ],



            buttons: [
                //{extend: 'copy'},
                //{extend: 'csv'},
                //{extend: 'excel', title: 'ExampleFile'},
                //{extend: 'pdf', title: 'ExampleFile'},

                  {extend: 'print',
                 customize: function (win){
                        $(win.document.body).addClass('white-bg');
                        $(win.document.body).css('font-size', '10px');

                        $(win.document.body).find('table')
                                .addClass('compact')
                                .css('font-size', 'inherit');

                }
                }
            ]

        });
});

Upvotes: 1

Views: 512

Answers (1)

CK8
CK8

Reputation: 359

I found the issues. I need to comments out the following lines.

            //"processing": true,
            //"serverSide": true,

now the code work. The reason being the searching and sorting are done on client side not on server side.

Upvotes: 1

Related Questions