AJAX sort descending on load

AJAX sort descending on load

dmitradmitra Posts: 6Questions: 0Answers: 0
edited March 2012 in DataTables 1.9
Hi there.

I posted this in general discussion by accident and I got no help. So I'm reposting here - hopefully that's okay. Here's my original post issue.

____________________________________
I am having an issue with this sorting the following. It loads everything fine and sorts by the correct column (the 1st), however, it's ascending. I would like to have it sort on load descending but am not sure how to do so. Any advice would be greatly appreciated. Thanks

Derrick

$('#myTable').dataTable({
"bProcessing": true,
"bAutoWidth": false,
"bJQueryUI": true,
"sAjaxSource": "/path/to/service/",
"aoColumns": [
{ "mDataProp": "LabNumber", "sType": "string"},
{ "mDataProp": "DateClosed" },
{ "mDataProp": "ConsumerName" },
{ "mDataProp": "Status" },
]
});

Replies

  • allanallan Posts: 63,491Questions: 1Answers: 10,470 Site admin
    edited March 2012
    Use the aaSorting parameter to define the default sorting that is applied to the table :-)

    Allan
  • dmitradmitra Posts: 6Questions: 0Answers: 0
    Hi Allan.

    Not sure where to place this parameter as I've tried the following but the code does not load the table - I just see "loading" and it just hangs. Any insight?


    $('#myTable').dataTable({
    "bProcessing": true,
    "bAutoWidth": false,
    "bJQueryUI": true,

    "aaSorting": [[0,'desc']],

    "sAjaxSource": "/path/to/service/",
    "aoColumns": [
    { "mDataProp": "LabNumber", "sType": "string"},
    { "mDataProp": "DateClosed" },
    { "mDataProp": "ConsumerName" },
    { "mDataProp": "Status" },
    ]
    });
  • allanallan Posts: 63,491Questions: 1Answers: 10,470 Site admin
    Most likely either a Javascript error or a JSON parsing error. What does the Firebug console say?

    The code you posted looks like what I would expect for what you want (minus the trailing comma in the aoColumns array which will be causing IE to error out).

    Allan
  • dmitradmitra Posts: 6Questions: 0Answers: 0
    Hi Allan.

    What am I looking for in Firebug specifically?
This discussion has been closed.