Handsontable example
by mpusarla
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.js"></script>
<script src="http://docs.handsontable.com/0.15.0-beta6/bower_components/handsontable/dist/pikaday/pikaday.js"></script>
<link rel="stylesheet" href="http://docs.handsontable.com/0.15.0-beta6/bower_components/handsontable/dist/pikaday/pikaday.css">
<script src="http://corecms:8081/include/js/jquery.js"></script>
<script src="http://code.jquery.com/ui/1.8.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.2/themes/smoothness/jquery-ui.css">
<div id="example1" class="hot handsontable"></div>
CSS
</style><!-- Ugly Hack due to jsFiddle issue -->
<script src="http://docs.handsontable.com/0.15.0-beta6/scripts/jquery.min.js"></script>
<script src="http://corecms:8081/include/js/handsontable.full.js"></script>
<link type="text/css" rel="stylesheet" href="http://corecms:8081/include/css/handsontable.full.css">
JavaScript
document.addEventListener("DOMContentLoaded", function() {
function getCarData() {
return [
["Mercedes", "A 160", "01/14/2012", 6999.9999],
["Citroen", "C4 Coupe", "12/01/2013", 8330],
["Audi", "A4 Avant", "11/19/2014", 33900],
["Opel", "Astra", "02/02/2015", 7000],
["BMW", "320i Coupe", "07/24/2016", 30500]
];
}
var
container = document.getElementById('example1'),
hot;
hot = new Handsontable(container, {
data: getCarData(),
colHeaders: ['Car', 'Model', 'Registration date', 'Price'],
columns: [
{
type: 'autocomplete',
source: ['Audi', 'BMW', 'Chrysler', 'Citroen', 'Mercedes', 'Nissan', 'Opel', 'Suzuki', 'Toyota', 'Volvo'],
strict: false
},
{
// 2nd cell is simple text, no special options here
},
{
type: 'date',
dateFormat: 'MM/DD/YYYY',
correctFormat: true,
defaultDate: '01/01/1900'
},
{
type: 'numeric',
format: '$ 0,0.00'
}
]
});
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();
});