Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handsontable .getData by div id is not working?

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?

like image 390
mkHun Avatar asked Sep 29 '17 06:09

mkHun


1 Answers

Finally got the answer

 $('#app .ht_master tbody td').each(function(){
    var text = $(this).text();
 });
like image 197
mkHun Avatar answered Oct 21 '22 17:10

mkHun