I'm new to Datatable and am trying to configure the Datatable, so that it fetches the data with ajax, displays it as a check-box, an anchor and a tab and allows a user to sort it. I have the ajax and formatting part, however when I try to sort the check-boxes it does nothing. I looked up the documented example and took the sort handler from it:
Code for sorting:
/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function (oSettings, iColumn) {
var aData = [];
$('td:eq(' + iColumn + ') input', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
aData.push(this.checked == true ? "1" : "0");
});
return aData;
}
Code for creating the checkbox:
$('#example').dataTable({
"bProcessing": true,
"sAjaxSource": "sources/myData.json",
"sAjaxDataProp": "items",
"aoColumns": [
{
"mData": function (source, type, val) {
if (source.Published)
return '<input type="checkbox" checked="checked"/>';
else
return '<input type="checkbox" />';
},
//"sType": "dom-checkbox",
"sSortDataType": "dom-checkbox"
//, "bSortable": false
},
{ "mData": "Author" },
{
"mData": function (source, type, val) {
return '<a href="' + source.Href + '">' + source.$name + '</a>';
}
}
]
});
The sorting function ( $.fn.dataTableExt.afnSortData['dom-checkbox']
is called and the data is returned, however the table isn't updated. (the code works but not for ajax tables).
Data sample:
{
"items": [
{
"$name": "a",
"Href": "http://google.com",
"Author": "a",
"Published": true
},
{
"$name": "c",
"Href": "http://www.whiskas.at/",
"Author": "a",
"Published": false
}
]
}