Multiple DataTables on the same page with different ajax sources
Will this not work? It uses the id rather than the class to uniquely identify each data table and attaches a separate source to each table based on the id.
var oTable = $('#FirstDataTableID').dataTable( {
"bProcessing": true,
"sAjaxSource": "/ajax/function",
"bSort": false,
"fnDrawCallback": function() {
//some click events initilized here
}
});
var oTable = $('#SecondDataTableID').dataTable( {
"bProcessing": true,
"sAjaxSource": "/ajax/other_function",
"bSort": false,
"fnDrawCallback": function() {
//some click events initilized here
}
});
I had the same problem, which I solved using a html5 data- attribute and initialization code similar to yours:
$('.dataTableServer').each(function () {
var source = $(this).attr("data-source");
$(this).dataTable({
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": source
});
});
that way you don't have to create an id for each dataTable