Upload jQuery Handsontable input

有些话、适合烂在心里 提交于 2020-01-01 06:37:10

问题


What is the best way to upload data entered by user in jQuery Handsontable back to Server to be saved into database?

The existing onChange callback seems to be very verbose to save input data using AJAX especially if user insert new data row above existing one. Looking for functionality to upload input data after complete the editing using Handsontable or jQuery

Here is the full code using jQuery to loop the input data and dump into text box in JSON format then submit to server. This process look ugly. looking for a cleaner way..

$('#btnGo').click(function() {

    var rowList = new Array();
    $("table tr").each(function() {
        var colList = new Array();
        $("td", this).each(function() {
            colList.push($(this).text());
        });
        rowList.push(colList);
    });
    $('#simple').val(JSON.stringify(rowList));
    console.log(rowList);
});​

回答1:


There is a build in method for getting the whole array of table data: .handsontable("getData")

You can use it like this:

$('#btnGo').click(function() {
  var rowList = $("#example9grid").handsontable("getData");
  $('#simple').val(JSON.stringify(rowList));
  console.log(rowList);
});​

Working example: http://jsfiddle.net/warpech/bwv2s/20/



来源:https://stackoverflow.com/questions/10831969/upload-jquery-handsontable-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!