Handsontable example
HTML
<div id="example1" class="hot handsontable"></div>
CSS
</style><!-- Ugly Hack due to jsFiddle issue -->
<script src="http://docs.handsontable.com/0.15.1/scripts/jquery.min.js"></script>
<script src="http://docs.handsontable.com/0.15.1/bower_components/handsontable/dist/handsontable.full.js"></script>
<link type="text/css" rel="stylesheet" href="http://docs.handsontable.com/0.15.1/bower_components/handsontable/dist/handsontable.full.min.css">
JavaScript
document.addEventListener("DOMContentLoaded", function() {
function getCarData() {
return [
["Nissan", 2012, "black", "black"],
["Nissan", 2013, "blue", "blue"],
["Chrysler", 2014, "yellow", "black"],
["Volvo", 2015, "white", "gray"]
];
}
var
container = document.getElementById('example1'),
hot;
data = getCarData();
hot = new Handsontable(container, {
data: data,
contextMenu: true,
colHeaders:true,
afterCreateCol: function(index, amount, source) {
columnTitle = this.getDataAtRow(0);
hot_changes = [];
need_new_name = true;
i = 1;
while (need_new_name) {
new_name = "New_Var" + i;
if (columnTitle.indexOf(new_name) === -1) {
need_new_name = false;
}
i++;
}
hot_changes.push([0, index, new_name]);
hot_changes.push([1, index, "Nominal"]);
this.setDataAtCell(hot_changes, source = "dataManagement");
},
afterChange: function (changes, sources) {
this.updateSettings({
minCols: changes[0][1] + 10
});
}
});
function bindDumpButton() {
if (typeof Handsontable === "undefined") {
return;
}
Handsontable.Dom.addEvent(document.body, 'click', function (e) {
var element = e.target || e.srcElement;
if (element.nodeName == "BUTTON" && element.name == 'dump') {
var name = element.getAttribute('data-dump');
var instance = element.getAttribute('data-instance');
var hot = window[instance];
console.log('data of ' + name, hot.getData());
}
});
}
bindDumpButton();
});