I'm trying to do dataTables server side using version 10.4.1.
I'm selecting data from different views with different columns and number of columns so it has to be dynamic. Some of them don't contain so much data, but some of them have up to 400.000 rows and 30 columns. But I'm always getting the above error.
Here is my client-side code
$('.button').click(function (event) {
event.preventDefault();
if ($('#GroupElement_Id option:selected').val() != '') {
var viewname = $('#GroupElement_Id option:selected').val();
// if data-table has been initialized then destroy it
if ($('#gem-table').hasClass('dataTable')) {
var table = $('#gem-table').DataTable();
// remove all rows. important to call before destroy.
table.clear();
// remove those enhancements and return the table to its original un-enhanced state
// call if create new tables based on new criteria with different initialisation settings
table.destroy();
// empty in case the columns change
$('#gem-table thead tr').empty();
$('#gem-table tbody').empty();
$('#gem-table tfoot tr').empty();
}
// Ajax call that gets the data
$.ajax({
type: 'GET',
contentType: 'application/json; charset=utf-8',
url: apiBaseUmbraco + 'gem/gemdataserverside/',
data:
{
'viewname': viewname,
'all': $('#all-gem-rows').is(':checked') ? 1 : 0
},
dataType: 'JSON',
beforeSend: function () {
$('.ajax-loader').show();
},
success: function (response) {
var tableColumns = jQuery.parseJSON(response).columns;
var columns = [];
var headers = '';
var footers = '';
// build up table header, footer
// and columns JSON array for the data-table
$.each(tableColumns, function (index, value) {
headers += '<th>' + value + '</th>';
footers += '<th>' + value + '</th>';
var headerObj = new Object();
headerObj['sName'] = value;
columns.push(headerObj);
});
// insert header and footer into the table
$('#gem-table thead tr').html(headers);
$('#gem-table tfoot tr').html(footers);
$('#gem-table').dataTable({
'bServerSide': true,
'sAjaxSource': apiBaseUmbraco + 'gem/gemdataserverside/?viewname=' + viewname + '&all=' + ($('#all-gem-rows').is(':checked') ? '1' : '0'),
'bProcessing': true,
'aoColumns': columns,
dom: 'T<"clear">lfrtip',
'tableTools': {
'sSwfPath': '/swf/copy_csv_xls_pdf.swf'
},
'responsive': true,
'lengthMenu': [[25, 50, 100, -1], [25, 50, 100, 'All']],
'drawCallback': function (settings) {
$('.ajax-loader').hide();
},
});
// scroll down to data-table
$('html, body').animate({
scrollTop: $('#gem-table_wrapper').offset().top
}, 1000);
},
error: function (result) {
alert('Service call failed: ' + result.status + ' Type :' + result.statusText);
}
});
} else {
}
});
Hope someone can help.
Thanks in advance.
Best,
Bilal