I'm trying to get the filled data using the div id but it is throwing $container.data(...) is undefined
.
<!-- ... -->
<div id="app" style="width: 500px; height: 200px;"></div>
</div>
<button id="app_id" onclick="json()">Json</button>
I have tried the following code to get the filled data:
var rowHead = colAr;
var colHead = dataObj[idname].col;
var data = [[]],
container = document.getElementById("app"),
selectFirst = document.getElementById('selectFirst'),
rowHeaders = document.getElementById('rowHeaders'),
colHeaders = document.getElementById('colHeaders'),
hot;
hot = new Handsontable(container, {
minRows:rowHead.length,
minCols:colHead.length,
startRows: 5,
startCols: 5,
rowHeaders: rowHead,
colHeaders: colHead,
contextMenu: false,
outsideClickDeselects: false,
removeRowPlugin: true
});
hot.loadData(data);
function json() {
var $container = $("#app");
var handsontable = $container.data('handsontable').getData();
console.log(handsontable);
/*
var htContents = hot.getData();
var jsonObj = {};
for (var i = 0; i < htContents.length; i++)
{
jsonObj[rowHead[i]] = htContents[i];
}
console.log(jsonObj);
*/
}
But it is throwing error, instead I tried with another option:
var cont = hot.getData();
console.log(cont);
This is working. But I have multiple tables so I need to get the data by the particular table using the div id, what is the problem in my code?
handsontable()
on#app
? What ishot
? Any errors in the console? We need to see much more of your code to be able to help you. – Drier$container.data(...) is undefined
error. – Costplus$().ready with $().click
all are the method showing the same error as$container.data(...) is undefined
. – Costplusdiv
withid="app"
doesn't havehandsontable
data attribute. – Drennen