Footer data

Adding fixed calculations the Jspreadsheet footers.



Source code

<html>
<script src="https://jspreadsheet.com/v7/jspreadsheet.js"></script>
<script src="https://jsuites.net/v4/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v4/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://jspreadsheet.com/v7/jspreadsheet.css" type="text/css" />

<div id="spreadsheet"></div>

<script>
var 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"],
];

// A custom method to SUM all the cells in the current column

var SUMCOL = function(instance, columnId) {
    var total = 0;
    for (var 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: 'M2RiZjdmY2MyMmIzM2JlMGQxZjZkODg5YzcxNjIxN2IxZWUzZjI3MDJlNTAyNDhkZTk1YzM1NTRiN2NkN2UyOTA5NzRmOWVkOWNlYmJkMmVkMjI4MzE0MzU1YTViZWQ2OGMwNDlkYmRkOTc5ZGYzOGExN2YwZGI2ZDYyMTU5YmYsZXlKdVlXMWxJam9pY0dGMWJDNW9iMlJsYkNJc0ltUmhkR1VpT2pFMk5EWXdPVEk0TURBc0ltUnZiV0ZwYmlJNld5SmpjMkl1WVhCd0lpd2lhbk5tYVdSa2JHVXVibVYwSWl3aWQyVmlMbUZ3Y0NJc0ltcHpjSEpsWVdSemFHVmxkQzVqYjIwaUxDSnFaWGhqWld3dWJtVjBJaXdpYkc5allXeG9iM04wSWwwc0luQnNZVzRpT2lJekluMD0=',
});
</script>
</html>