Datatable Sorting

Datatable Sorting

bhupendraramanibhupendraramani Posts: 4Questions: 0Answers: 0
edited August 2012 in General
Hi Allan ,
I have 4 columns in my datatable and by default I want sorting by 1st column always. I am using 1.6.2 version of datatable.

I have written following code on document.ready function

tTable = $("#ticketsTable").dataTable({
bProcessing: true,
bServerSide: true,
sAjaxSource: a,
fnServerData: fnDataTablesPipeline,
fnDrawCallback: afterTableDraw,
fnInitComplete: drawBorders,
"sScrollY": "200",
"bScrollCollapse": true,
"iDisplayStart": displayStart,
"iDisplayLength": lastIndex,
"bScrollInfinite": true,
"bScrollCollapse": true,
"sScrollY": "100px",
"iScrollLoadGap": 10,
bJQueryUI: true,
oLanguage: { sProcessing: "", sZeroRecords: "SeatKarma found no tickets for this event.", sSearch: "", oPaginate: { sNext: ">", sPrevious: "<"} }
});

Thanks in Advance
Regards
Bhupendra

Replies

  • cserfosscserfoss Posts: 11Questions: 0Answers: 0
    You can use the "aaSorting" option to set your initial sort and the bSortable option to disallow sorting for a particular column:

    [code]
    var oTable = $('#example').dataTable({
    "aaSorting": [[1,"asc"]], // Sort on the first visible column in ascending order
    });
    [/code]

    [code]
    "aoColumnDefs": [
    { "aTargets": [ "COL_SAMPLE" ],
    "bSortable": false,
    }
    ]
    });
    [/code]
  • bhupendraramanibhupendraramani Posts: 4Questions: 0Answers: 0
    thanks for your response...
    Its working fine for first time , but when I am going to sort another column and refreshing page then it will not give me default sorting by 1st column
  • arjun_adhikariarjun_adhikari Posts: 32Questions: 0Answers: 0
    hi bhupendreramani,

    instead of doing clientside sorting why dont you let your serverside logic do all the sorting for you that way when the table is refreshed sorting is based on the first column only or any other column you want it to be.

    Arjun
  • bhupendraramanibhupendraramani Posts: 4Questions: 0Answers: 0
    thanks Arjun..
    Resolve .... your trick works for me
This discussion has been closed.