Variable Columns Sorting not working on other then string datatypes

Variable Columns Sorting not working on other then string datatypes

kmmurali80kmmurali80 Posts: 2Questions: 0Answers: 0
edited May 2011 in General
Hi,
Our Datatables Initialization has "aoColumns": resultColumns where resultColumns can vary depending on selection
and the table is build dynamically on the fly. I am not able to assign sorting or sTypes on individual columns because they can vary each time depending on the order of selection. DataTable is not recognizing the datatypes depending on the data it only sorts by string.


Please see the complete defnition of init table
"[Code]
resultSetTable = $('#tblResults').dataTable({
"iDisplayLength": 10,
"bLengthChange": true,
"aLengthMenu": [[10, 25, 50, 100, 10000], [10, 25, 50, 100, "Show All"]],
"sDom": 'T<"clear">lfrtip',
"oTableTools": { "sSwfPath": "Styles/swf/copy_cvs_xls_pdf.swf" },
"bJQueryUI": true,
"aoColumns": resultColumns,
"bFilter": true,
"bProcessing": true,
"bServerSide": true,
"bAutoWidth": true,
"bStateSave": false,
"sAjaxSource": globalServiceUrl + 'GetSortReport',
"sScrollX": "100%",
"sScrollY": 400,
"sScrollXInner": "110%",
"sScrollYInner": "110%",
"bScrollCollapse": true,
"aoColumnDefs": [ { "sType": "Date", "aTargets": [ 1 ] } ],
"fnServerData": function (sSource, aoData, fnCallback) {
var sEcho, iDisplayStart, iDisplayLength, sSearch, iSortColIndex, sSortColDir


for (var index = 0; index < aoData.length; index++) {
if (aoData[index].name == "sEcho") reportParam.sEcho = aoData[index].value;
if (aoData[index].name == "iDisplayStart") reportParam.iDisplayStart = aoData[index].value;
if (aoData[index].name == "iDisplayLength") reportParam.iDisplayLength = aoData[index].value;
if (aoData[index].name == "sSearch") reportParam.sSearch = aoData[index].value;
if (aoData[index].name == "iSortCol_0") reportParam.iSortColIndex = aoData[index].value;
if (aoData[index].name == "sSortDir_0") reportParam.sSortColDir = aoData[index].value;
} [/Code]"


Any ideas of how to acheive this functionality.

Replies

  • allanallan Posts: 64,978Questions: 1Answers: 10,759 Site admin
    You are using server-side processing ("bServerSide": true), so setting sType will have no effect on the table, since the sorting (which sType will effect) is done on the server-side, not by DataTables. I presume you have an SQL db somewhere for your data source - whatever is calling that needs to be aware of the data types so it can sort accordingly.

    Allan
  • kmmurali80kmmurali80 Posts: 2Questions: 0Answers: 0
    Thanks for the response Allan,
    That was indeed correct the issue is now fixed.

    Thanks again
This discussion has been closed.