Created
August 31, 2023 15:38
-
-
Save akinozgen/2b81f2f4cf6d706798d7f13a637af6c5 to your computer and use it in GitHub Desktop.
Datatables excelHtml5 number summary cell with a label
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
customize: function (xlsx) { | |
let sheet = xlsx.xl.worksheets['sheet1.xml']; | |
let numrows = 0; | |
let total = 0; | |
const valueColumnOrder = 7; // nth-child, start with 1 | |
const totalColumnOrder = 'G'; // spreadsheet column letter, G == 7 | |
const totalLabel = 'Total'; | |
const shouldReplaceCommas = true; | |
$('row', sheet).each(function () { | |
// Get current row | |
var row = $(this); | |
numrows++; | |
// Skip header rows | |
if (numrows > 2) { | |
// Get the 'tutar' value for each row and add to total | |
let totalValue = $(`c:nth-child(${valueColumnOrder}) v`, row)[0].textContent; | |
if (shouldReplaceCommas) { | |
totalValue = totalValue.replace(',', '.'); | |
} | |
total += parseFloat(totalValue); | |
} | |
}); | |
numrows++; | |
$('row:last', sheet).after(`<row r="${numrows}"><c t="inlineStr" r="${totalColumnOrder}${numrows}"><is><t>${totalLabel}</t></is></c><c t="inlineStr" r="${totalColumnOrder}${numrows}"><is><t>${total.toFixed(2)}</t></is></c></row>`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment