Skip to content Skip to sidebar Skip to footer

Datatable: Sorting Not Working

Please help. I am not sure where I am going wrong I want the table to be sorted by the first column. I tried several variations, but sort is not working properly dataTable = $('#de

Solution 1:

This is what I did, and the sorting works on the first column.

@{
    Layout = null;
}

<!DOCTYPE html><html><head><metaname="viewport"content="width=device-width" /><title>Index62</title><scriptsrc="~/Scripts/jquery-1.12.4.min.js"></script><scriptsrc="~/Scripts/DataTables/jquery.dataTables.min.js"></script><linkhref="~/Content/DataTables/css/jquery.dataTables.min.css"rel="stylesheet" /><scripttype="text/javascript">
        $(document).ready(function () {
              $('#example').
                dataTable({
                "processing": true,
                "serverSide": true,
                "info": true,
                "stateSave": true,
                "ajax": {
                    "url": "/Home/AjaxGetJsonData",
                    "type": "GET"
                },
                "columns": [
                    { "data": "Name", "orderable": true },
                    { "data": "Age", "orderable": false },
                    { "data": "DoB", "orderable": true }
                ],
                "order": [[0, "asc"]]
            });
        });

    </script></head><body><divstyle="margin:30px;"><tableid="example"class="display"cellspacing="0"width="100%"><thead><trstyle="text-align:left;"><th>Name</th><th>Age</th><th>DoB</th></tr></thead><tfoot><trstyle="text-align:left;"><th>Name</th><th>Age</th><th>DoB</th></tr></tfoot></table></div></body></html>

Solution 2:

You can try like this

dataTable = $("#deptDtTable").dataTable({
        "bFilter" : false
         .......
        "aaSorting": [[ 0, "desc" ]] // Sort by first column descending
         ......
}); 

Post a Comment for "Datatable: Sorting Not Working"