Footer data
Adding fixed calculations the Jspreadsheet data grid footers.
<html>
<script src="https://jspreadsheet.com/v7/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://jspreadsheet.com/v7/jspreadsheet.css" type="text/css" />
<div id="spreadsheet"></div>
<script>
let data = [
['Cheese', 10, 6.00, "=B1*C1"],
['Apples', 5, 4.00, "=B2*C2"],
['Carrots', 5, 1.00, "=B3*C3"],
['Oranges', 6, 2.00, "=B4*C4"],
];
jspreadsheet.setExtensions({ formulas: formula })
// A custom method to SUM all the cells in the current column
let SUMCOL = function(instance, columnId) {
let total = 0;
for (let j = 0; j < instance.options.data.length; j++) {
if (Number(instance.records[j][columnId-1].element.innerHTML)) {
total += Number(instance.records[j][columnId-1].element.innerHTML);
}
}
return total;
}
jspreadsheet(document.getElementById('spreadsheet'), {
data: data,
minDimensions: [4,10],
footers: [
[
'Total',
'=SUMCOL(TABLE(), COLUMN())',
'=SUMCOL(TABLE(), COLUMN())',
'=SUMCOL(TABLE(), COLUMN())'
]
],
columns: [
{ width:'400px' }
],
license: 'NjYzYzNiMWQzMjgxODVjNTYwMjEyYTc1MmY1ZWMwY2RmZmY5NDg1OThkZjdlMjE4NmY4NDJlYTdmZTVjOTc1NzdlODNjNzI4YzM5ZTRiZDIwYmVlNWFlNzgwZjYyZDAzZmUyZGZkYTIxOGE3NTZiODdmOGE2MGRiNzM4MDg0OTcsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNME9UUTNNakEyTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==',
});
</script>
</html>