Adding formulas to your spreadsheets
The example below shows how to use excel-like formulas on your javascript spreadsheet.
<html>
<script src="https://jspreadsheet.com/v7/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jspreadsheet.com/v7/jspreadsheet.css" type="text/css" />
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<div id="spreadsheet"></div>
<script>
let data = [
[ 'Crayons Crayola only (No Rose Art)', 2, 5.13, '=B1*C1' ],
[ 'Colored Pencils Crayola only', 2, 4.41, '=B2*C2' ],
[ 'Expo Dry-erase Markers Wide', 4, 3.00, '=B3*C3' ],
[ 'Index Cards Unlined', 3, 6.00, '=B4*C4' ],
[ 'Tissues', 10, 1.90, '=B5*C5' ],
[ 'Ziploc Sandwich-size Bags', 5, 1.00, '=B6*C6' ],
[ 'Thin Markers Crayola only', 2, 3.00, '=B7*C7' ],
[ 'Highlighter', 4, 1.20, '=B8*C8' ],
[ 'Total', '=SUM(B1:B8)', '=ROUND(SUM(C1:C8), 2)', '=SUM(D1:D8)' ],
];
jspreadsheet(document.getElementById('spreadsheet'), {
data: data,
columns: [
{ type: 'text', title:'Product', width:'300' },
{ type: 'text', title:'Qtd', width:'80' },
{ type: 'text', title:'Price', width:'100', mask:'#.##0,00', decimal:',' },
{ type: 'text', title:'Total', width:'100' },
],
updateTable: function(instance, cell, col, row, val) {
if (cell.innerHTML == 'Total') {
cell.parentNode.style.backgroundColor = '#fffaa3';
}
if (col == 3) {
if (parseFloat(cell.innerText) > 10) {
cell.style.color = 'red';
} else {
cell.style.color = 'green';
}
}
},
columnSorting:false,
license: 'Mzk4YjAwM2FlZjMwZjUwYjZmYWNlNWI4ZjJhYzUwZmNkOWM5NGQzMDdjMDNiNDk5OTE0NGFlMTA1NTNlZjMzYzBiNmQ4NTM1YmNmMDk1OTUzNmUwY2FiM2NiMmVkNDRhMmM4MDY3MzljZDk4YjgyNThhMDJhZjE1NzRkMjhhNWIsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNeU16TXlOalkwTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==',
});
</script>
</html>