DataTables Custom Header Text on JSON
DataTables Custom Header Text on JSON
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]
[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]
This discussion has been closed.
Replies
[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
Allan