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?
Finally got the answer
$('#app .ht_master tbody td').each(function(){
var text = $(this).text();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With