1
 $('#StudentTable').dataTable({

    "aaSorting": [],
    "bSorting": false,
    "bProcessing": false,
    "bPaginate": false,
    "bFilter": false,
    "bDestroy": false,
    "bAutoWidth": true,
    "sScrollY": "224px",
    "aoColumns": [
                    { "sTitle": "StudentId" },
                    { "sTitle": "Name" },
                    { "sTitle": "Address" },
                    { "sTitle": "Mobileno" },
                    { "sTitle": "Email" }
                ],

    "aaData": Students
});

I am binding data to datatable dynamically...but problem is sorting not working properly.. it will sort Studentid 1 to 10 properly but if it is gretter then 10 it will come some studentid in top .you can see bellow output of sorting

See output of sorting order

1
  • 2
    Yes - Perhaps this is treated as string and sorting like string. Commented Dec 12, 2013 at 9:49

1 Answer 1

3

You need to tell dataTable what kind of datatype each column exist of. Set the StudentId sType to "sType": 'numeric' and it should sort correct.

$('#StudentTable').dataTable({

"aaSorting": [],
"bSorting": false,
"bProcessing": false,
"bPaginate": false,
"bFilter": false,
"bDestroy": false,
"bAutoWidth": true,
"sScrollY": "224px",
"aoColumns": [
                { "sTitle": "StudentId", "sType": 'numeric'  },
                { "sTitle": "Name" },
                { "sTitle": "Address" },
                { "sTitle": "Mobileno" },
                { "sTitle": "Email" }
            ],

"aaData": Students

});

Sign up to request clarification or add additional context in comments.

2 Comments

if it is numeric concatenated with string.which data type need to use
If your column dont follow regular datatypes you should implement a custom sort order function. Se this page for more info. datatables.net/plug-ins/sorting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.