Handsontable example
HTML
<script src="https://docs.handsontable.com/pro/1.5.1/bower_components/handsontable-pro/dist/handsontable.full.min.js"></script>
<link rel="stylesheet" href="https://docs.handsontable.com/pro/1.5.1/bower_components/handsontable-pro/dist/handsontable.full.min.css">
<button class='filterData'>1. filter data</button>
<button class='newRow'>2. Add row</button>
<button class='updateSettings'>3. Update settings</button>
<div>
<div id="example1" class="hot handsontable htRowHeaders htColumnHeaders"></div>
</div>
CSS
.handsontable td.newRowBlock {
background: blue;
color: white
}
button{
display:block;
}
JavaScript
document.addEventListener("DOMContentLoaded", function() {
var dataObj = [
['AA', '10/10/2010', 'B'],
['AB', '10/10/2010', 'B'],
['AC', '10/10/2010', 'B'],
['AD', '10/10/2010', 'B'],
['C', '12/12/2012', 'D'],
['E', '01/01/2013', 'F']
];
var example1 = document.getElementById('example1');
var hot = new Handsontable(example1, {
data: dataObj,
columns: [
{type: 'text'},
{type: 'date', dateFormat: 'M/D/YYYY'},
{type: 'numeric'}
],
colHeaders: true,
rowHeaders: true,
dropdownMenu: true,
filters: true
});
var newRow = document.querySelector('.newRow');
newRow.addEventListener('click', function(){
var newRow = 2;
console.log('last visible row is ' + newRow);
hot.alter('insert_row',newRow);
//hot.getCellMeta(newRow, 0).className = 'newRowBlock';
//hot.getCellMeta(newRow, 1).className = 'newRowBlock';
//hot.getCellMeta(newRow, 2).className = 'newRowBlock';
hot.render()
});
var filterData = document.querySelector('.filterData');
filterData.addEventListener('click', function() {
hot.getPlugin('filters').addFormula(0, 'contains', ['A']);
hot.getPlugin('filters').filter();
})
var updateSettings = document.querySelector('.updateSettings');
updateSettings.addEventListener('click', function() {
hot.updateSettings();
});
});