I have two tables on one page. Using javascript and Datatable to populate data into the tables gives the error below but works when i use only one table.
DataTables warning: table id=gvCustomers - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "dashboard.aspx/gvCustomersRetiring",
data: '{admindashboard: ' + JSON.stringify(admindashboard) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) { alert(response.responseText); },
error: function (response) { alert(response.responseText); }
});
});
function OnSuccess(response) {
$(function () {
var table2 = $('#gvCustomersRetiring').DataTable({
"responsive": true, "lengthChange": true, "autoWidth": false,
lengthMenu: [[10, 20, -1], [10, 20, "All"]],
"buttons": ["copy", "excel", "pdf", "print"],
data: response.d,
columns: [
{ 'data': 'staffno' },
{ 'data': 'staffname' },
{ 'data': 'dob' },
{ 'data': 'dept' },
{ 'data': 'dor' }
]
});
});
};
</script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "dashboard.aspx/loaddepartmenttotal",
data: '{admindashboard: ' + JSON.stringify(admindashboard) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) { alert(response.responseText); },
error: function (response) { alert(response.responseText); }
});
});
function OnSuccess(response) {
$(function () {
var table1 = $('#gvCustomers').DataTable({
"responsive": true, "lengthChange": true, "autoWidth": false,
lengthMenu: [[10, 20, -1], [10, 20, "All"]],
"buttons": ["copy", "excel", "pdf", "print"],
data: response.d,
columns: [
{ 'data': 'department' },
{ 'data': 'departmenttotal'}]
});
});
};
</script>