Records Not Appearing In Order in DataTables

Records Not Appearing In Order in DataTables

tinker1123tinker1123 Posts: 22Questions: 0Answers: 0
edited December 2012 in General
Hi,

I'm using AJAX to send data to DataTables, without server side processing.

My logs show that the JSON leaving the server is in order, but the order gets scrambled by the time it is displayed in DataTables.

This is the case both with IE 8 and FF 16.01.

Does DataTables by default sort on a particular column and if so is there a way to turn that off?

Here is my table code:

[code]

//Staff VECI for 540733
$(document).ready(function() {
$('#540733_staff_veci_table').dataTable( {
"bPaginate": false,
"sScrollY": "250px",
"bScrollCollapse": true,
"bFilter": false,
"bServerSide": false,
"sServerMethod": "POST",
"sAjaxSource": "/nsd/staffvecitable",
"aoColumns": aoColumns,
"bProcessing": true,
"bDeferRender": true,
"fnServerParams": function ( aoData ) { aoData.push( { "name": "person_id", "value": "540733" } );}
} );
} );

[/code]

Here are the first 3 rows/records in my JSON string, in alphabetical order by last name, first name, middle name:

[code]
{
"aaData" : [ {
"person_id" : "3304",
"fullname" : "Campbell, Billy J",
"email_address" : "billy.j.campbell@acme.com",
"emergency_email_address" : "buffet@margaritaville.com",
"emergency_cell" : "",
"emergency_sms" : ""
}, {
"person_id" : "61885",
"fullname" : "Gao, Paul",
"noaa_email_address" : "someotherstupid.email@noaa.gov",
"emergency_email_address" : "",
"emergency_cell" : "",
"emergency_sms" : ""
}, {
"person_id" : "661935",
"fullname" : "Test0009, Jan0009",
"noaa_email_address" : "",
"emergency_email_address" : "",
"emergency_cell" : "",
"emergency_sms" : ""
}, {
[/code]

However in Datatables the first 3 names are

Cambell
Vargas
Gao

not alphabetical order or reversed alphabetical order.

Any ideas on what I can look at it as the source of the problem?

Thanks much in advance

Steve

Replies

  • tinker1123tinker1123 Posts: 22Questions: 0Answers: 0
    edited December 2012
    I fixed this by adding the link "bSort": false to the table initialization. They can't sort the table now, but they don't need too and it is in the order I want:

    [code]

    //Staff VECI for 540733
    $(document).ready(function() {
    $('#540733_staff_veci_table').dataTable( {
    "bPaginate": false,
    "sScrollY": "250px",
    "bScrollCollapse": true,
    "bFilter": false,
    "bServerSide": false,
    "sServerMethod": "POST",
    "sAjaxSource": "/nsd/staffvecitable",
    "aoColumns": aoColumns,
    "bProcessing": true,
    "bDeferRender": true,
    "bSort": false,
    "fnServerParams": function ( aoData ) { aoData.push( { "name": "person_id", "value": "540733" } );}
    } );
    } );


    [/code]
  • tinker1123tinker1123 Posts: 22Questions: 0Answers: 0
    edited December 2012
    Another alternative is to be put this under my initialization code

    [code]
    (document).ready(function() {
    var oTable = $('#540733_staff_veci_table'}_staff_veci_table').dataTable();
    // Sort immediately with column1
    oTable.fnSort( [[1,'asc']] );
    );
    [/code]

    I'm new to and find function callback syntax confusing, is there a way to tuck this code into the table initialization?
This discussion has been closed.