DataTables Custom Header Text on JSON

DataTables Custom Header Text on JSON

zwayzway Posts: 7Questions: 0Answers: 0
edited December 2010 in General
I'm having issues specifying custom header text for the column definitions. Here's a (severly shortened) version of the JS that I use...I should have a column named "Free Call Hour Reset Count" but instead it's named "FreeCallHourResetCount"...I thought that definining "sTitle" in columns with the matching "sName" for the variable did this, but apparently I'm mistaken?

[code]$(document).ready(function () {
$('#ptDataTable').dataTable({
"sDom": 'C<"clear">lfrtip',
"aoColumnDefs": [
{ "bVisible" : true, "aTargets" : [0]}
]],
"oColReorder" : {
"aiOrder": [ 44, ]
},
"bStateSave": true,
"bAutoWidth": false,
"bProcessing": false,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sAjaxSource": "[REDACTED]",
"fnServerData": function (sSource, aoData, fnCallback) {
functionToCall = fnCallback;
$.getJSON(sSource, aoData, fixData);
}
});
});
function fixData(data) {
columns = [ { "sTitle" : "Free Call Hour Reset Count", "sName" : "FreeCallHourResetCount" } ],
fixedData = new Array();
var c = 0;
for (var i in data) {
fixedData[c] = new Array();
fixedData[c][0] = data[i].FreeCallHourResetCount;
c++;
}
json = new Object();
json.aaData = fixedData;
json.aoColumns = columns;

finished = 1;
functionToCall(json);
new ColReorder($('#ptDataTable').dataTable(), { "aiOrder": [ 44 ] });
}[/code]

Replies

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    I've just tried this and it seems to work okay:

    [code]
    $(document).ready(function() {
    $('#example').dataTable( {
    "aoColumnDefs": [ {
    "sTitle": "Hello world",
    "aTargets": [ 0 ]
    } ]
    } );
    } );
    [/code]
    You do have a double closing square bracket just before 'oColReorder' which looks a bit odd - but would presumably have thrown a JS error.

    Allan
  • zwayzway Posts: 7Questions: 0Answers: 0
    Thanks, defining the ttile in aoColumnDefs instead of afterwards when I'm adding the data to the table worked.
  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Ah yes I see - to change the column title after initialisation you would need to use DOM methods since DataTables doesn't present an API method for that. A good idea for a plug-in sometime...

    Allan
This discussion has been closed.