Я использовал бесконечную прокрутку для загрузки данных в jQuery Datatable. В обратном вызове я делаю итоги столбцов цифр c и отображаю их. Можно ли включить итоги при экспорте данных в Excel или CSV, внизу столбцов? Вот так Total_in_Footer
$('#tblDiscount').DataTable({
serverSide: true, // true
ordering: false, // false
searching: false, // false
lengthChange: false, // pagesize
footer: true,
columnDefs: [{ targets: [14, 16, 17], className: 'dt-body-right' },
{targets:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,15],classname:'dt-body-left'}
],
//searching: true,
dom: 'frBtip',
async: false,
ajax: function (data, callback, settings) {
var skip = 0;
if (data.start == 0)
skip = 0;
else
skip = data.start + 50; //data.length;
$.ajax({
url: '/Utility/_GetTestData',
data: {
State: stat,
Zone: zon,
Amrac: amr,
Store: store,
Hierarchy: hirarcy,
DiscountType: discountType,
Itemcategorycode: itemcatCode,
Itemcode: code,
Period: period,
OfferNo: offernumber,
skipRows: skip,
limit: 50 //data.length
},
datatype: "Json",
async: false,
success: function (data) {
//var item = $.parseJSON(data);
var transferDate ='';
var parsedDate = '';
var expiryDate = '';
var parsedExpiryDate = '';
dataset = data.res;
countRecords = data.recordCount;
totalOfDiscount = data.sumDiscount;
totalOfNetValue = data.total_Net_Value;
totalOfQuantity = data.total_quantity;
$("#tblDiscount_paginate").hide();
for (var i = 0; i < data.res.length; i++) {
transferDate = data.res[i].TransDate;
parsedDate = moment(transferDate);
data.res[i].TransDate = parsedDate.format('DD-MM-YYYY');
expiryDate = data.res[i].ExpirationDate;
parsedExpiryDate = moment(expiryDate);
data.res[i].ExpirationDate = parsedExpiryDate.format('DD-MM-YYYY');
if (hirarcy == "I") {
out.push([data.res[i].state, data.res[i].zone,b
data.res[i].Depot, data.res[i].StoreCode, data.res[i].OfferType, data.res[i].DiscountType,
data.res[i].OfferNo, data.res[i].Description, data.res[i].ReceiptNo, data.res[i].TransDate,
data.res[i].Category, data.res[i].ItemCode, data.res[i].LotNo, data.res[i].ExpirationDate,
data.res[i].Quantity, data.res[i].FreeItem, data.res[i].NetValue, data.res[i].Discount]);
}
else if (hirarcy == "S") {
out.push([data.res[i].state, data.res[i].zone, data.res[i].amro,
data.res[i].StoreCode, data.res[i].OfferType, data.res[i].DiscountType,
data.res[i].OfferNo, data.res[i].Description, data.res[i].ReceiptNo, data.res[i].TransDate,
data.res[i].Category, data.res[i].ItemCode, data.res[i].LotNo, data.res[i].ExpirationDate,
data.res[i].Quantity, data.res[i].FreeItem, data.res[i].NetValue, data.res[i].Discount]);
}
else if (hirarcy == "F") {
out.push([data.res[i].state, data.res[i].zone,data.res[i].rac,
data.res[i].StoreCode, data.res[i].OfferType, data.res[i].DiscountType,
data.res[i].OfferNo, data.res[i].Description, data.res[i].ReceiptNo, data.res[i].TransDate,
data.res[i].Category, data.res[i].ItemCode, data.res[i].LotNo, data.res[i].ExpirationDate,
data.res[i].Quantity, data.res[i].FreeItem, data.res[i].NetValue, data.res[i].Discount]);
}
}
//console.log(out.length);
},
//data: dataset,
//columns: [
// {
// title: "TransDate",
// render: function (data, type, row, meta) {
// var d = new Date(row[1]);
// var ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d)
// var mo = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(d)
// var da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d)
// return `${ye}-${mo}-${da}`;
// }
// }
//],
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 500) {
alert('Internal error: ' + jqXHR.responseText);
} else {
alert('Please revise your FILTER selection as the \n' +
'information You are fetching has more than 1 lac Records');
location.reload(true);
}
}
});
setTimeout(function () {
callback({
draw: data.draw,
data: out,
recordsTotal: parseInt(countRecords),
recordsFiltered: parseInt(countRecords)
});
}, 50); // scroll request size
}, //end of ajax call for controller
scrollY: 500, // div height
scrollX: true,
scroller: {
loadingIndicator: true
},
footerCallback: function (row, data, start, end, display) {
var api = this.api()
var json = api.ajax.json();
$(api.column(17).footer()).html(totalOfDiscount);
var api = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function (i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '') * 1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
total = api
.column(17)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
// Total over this page
pageTotal = api
.column(17, { page: 'current' })
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
//// Update footer
$(api.column(17).footer()).html('Total:' + totalOfDiscount);
$(api.column(16).footer()).html('Total:' + totalOfNetValue);
$(api.column(14).footer()).html('Total:' + totalOfQuantity);
}
});
Я просто хотел, чтобы итоги экспортировались в CSV вместе со всеми данными.