Datatables searching/ sorting is not working in serverside processing.

Datatables searching/ sorting is not working in serverside processing.

manuvarghesemanuvarghese Posts: 3Questions: 1Answers: 0

Datatables searching/ sorting is not working in serverside processing. while typing search textbox an ajax request is made and return successfully with the search result. But these result is not reflected in datatables.

<table id="example" class="display" style="width:100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>phone</th>
            <th>email</th>

        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>phone</th>
            <th>email</th>
        </tr>
    </tfoot>
</table>
<script>
    $(document).ready(function () {
        //alert('doc');
        $('#example').DataTable({
            "serverSide": true,
            "ajax": {
                "url": "index.php?r=patient/list",

            },
            columns: [
                {data: 'name'},
                {data: 'phone'},
                {data: 'email'}
            ]
        });
    });
</script>

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @manuvarghese ,

    It definitely works fine, see the example here.

    The problem is likely to be with your returned data. Can you post the JSON here, please. Note that the draw should be incrementing with each response. It would be worth looking at the Ajax tab in the example above, and seeing if your responses are similar.

    Cheers,

    Colin

  • manuvarghesemanuvarghese Posts: 3Questions: 1Answers: 0

    ```
    {
    "data":[
    [
    "Sangeetha Mohan",
    "9877777777",
    "sangeetha@gmail.com"
    ],
    [
    "Madhu Mohan",
    "9547863210",
    "madhu@gmail.com"
    ],
    [
    "wsd",
    "9876543219",
    "wdfc@fdsfg.com"
    ],
    [
    "wre",
    "0987675432",
    "eee@hmai.com"
    ],
    [
    "Manu Varghese",
    "9876543210",
    "manu.varghese@gmail.com"
    ],
    [
    "Vinu Varghese",
    "9876543210",
    "vinu.varghese@gmail.com"
    ],
    [
    "Tom Varghese",
    "9876543200",
    "manu.varghese@gmail.com"
    ]
    ],
    "draw":1,
    "options":[

    ],
    "recordsTotal":7,
    "recordsFiltered":7
    }

  • manuvarghesemanuvarghese Posts: 3Questions: 1Answers: 0

    @colin Po thanks,
    actually, the problem is I forget to increment the draw parameter every time. now its corrected.

This discussion has been closed.