I'm new in Handsontable.
I want to call Handsontable's method such as getData or selectCell. I have already tried out what the documentation is saying but it doesn't work.
Below is my JavaScript (jQuery) code:
$(document).ready(function () {
var test;
$.ajax({
type: 'POST',
url: 'accounting/ajax/ajaxLoadForViewAccount.php',
datatype: 'script',
data: {
tbname:tbname
},
success: function (response) {
test = JSON.parse(response);
var data = new Array();
var headerName = new Array();
var i=0;
for(i=0;i<test.room_num.length;i++){
var obj = {room_num:test.room_num[i],rental_fee:test.rental_fee[i]};
data.push(obj);
headerName[i] = test.room_num[i];
}
var container = document.getElementById('example');
var hot;
hot = new Handsontable(container, {
data: data,
colWidths: [80, 80],
rowHeaders: headerName,
colHeaders: ['room_num','rental_fee']
});
},
error: function () {
alert('error');
}
});
$('#submit').click(function () {
$('#example').append("<p>Testtttttttttttttttttttttttttttttttttttttt</p>");
$('#example').handsontable('setDataAtCell',1,1,'10000');
alert('test');
});
});
According to my code, after I click the submit button the example div is appended with "Testtttttttttttttttttttt" that means $('example') selector should work fine. In addition the 'test' alert also appears. However the method setDataAtCell doesn't work.
Consider always using the
hotinstance variable to access the instance. In your case: