I’m using HandsOnTables with a web2py app. All seems to work well, except that I cannot get the alter(‘row_above’) or alter(‘row_below’) to work. In the context menu, they are grayed out, and if I invoke them in code, nothing happens. Some digging around turned up a post (somewhere) that these two don’t work unless the data source is an array. In fact, when I replace the web2py data source with an array in the HTML for the view, the two add row commands do work as advertised.
The two alter functions in the context menu work with this:
$(document).ready(function() {
var data = [
{
"id":1,
"last_name":"Abbrederis",
"first_name":"Jason",
"pos":"WR"
},
{
"id":2,
"last_name":"Abbrederis",
"first_name":"Jason",
"pos":"WR"
},
{
"id":3,
"last_name":"Adams",
"first_name":"Davante",
"pos":"WR"
}
];
var hotElement = document.getElementById('list');
datatable = new Handsontable(hotElement, {
data: data,
<...snip rest of table configuration...>
They do not work with this:
var data = {{=XML(injuries.json())}}
var hotElement = document.getElementById('list');
datatable = new Handsontable(hotElement, {
data: data,
<...snip rest of table configuration...>
If I directly invoke datatable.alter(‘insert_row’,0), I get no error, but nothing happens.
How can I make the context menu options “Insert row above” and “Insert row below” work when the datasource is JSON from web2py?