Developing Spreadsheets with Handson Table

Asked 2 years ago, Updated 2 years ago, 79 views

We use HandsonTable to develop spreadsheets.
As for the source, the alert part below is for checking, and I'm actually trying to send it to the server by ajax.

<!DOCTYPE html>
<html lang="ja">
<head>
  <metacharset="utf-8">
  <link rel="stylesheet" href="css/handsontable.full.css">
  <scriptsrc="js/jquery.min.js"></script>
  <script src="js/handsontable.full.js">/script>
  <script>
  $(function(){
    var logs = $('#logs'),
    gridContainer= document.getElementById('grid'),
    selectedRow = 0,
    selectedCol = 0,
    gridTable = new Handsontable(gridContainer, {
        data —getData(),
        minSpareRows—1,
        rowHeaders: true,
        contextMenu:true,
        afterChange:function(changes,source){
            if(source=='edit'){
                for (vari=0; i<changes.length;i++) {
                    var rowChange=changes[i];
                }
            }
        },
    });
    $(document).on('click', '#btn-consoledata', function(e){
        var statdata=gridTable.getData();
        alert(statdata);
    });
  });
  vargetData=function(){
    return [
        ['A', 'B', 'C',]
        ["1","2","3"],
        ["4","5","6"],
        ["7","8","9"],
    ];
  };
  </script>
</head>
<body>
    <h1>test</h1>
    <div><button id="btn-consoledata">OK</button></div>
    <divid="grid"></div>
</body>
</html>

Run this source as follows:
①Display Screen
Enter a description of the image here
②Modify Data
Enter a description of the image here
③Press OK to display alerts
Enter a description of the image here

As mentioned above, I have been able to retrieve the change data, but
The data format is csv and the number of columns is unknown.
I would appreciate it if you could tell me how to get the number of columns or how to get the data in an array.
Thank you for your cooperation.

javascript jquery ajax

2022-09-30 11:13

1 Answers

Does getData() return a two-dimensional array?alert(statdata[0]); will only display the first line.
I feel like alert is just displaying a two-dimensional array as CSV.

  • There are methods called countRows() and countCols() to get rows and columns, which are useful.
  • If you want to retrieve data simply, you can retrieve it anywhere by using the above functions and getDataAtCell(row,col).
  • You can also use
  • or getDataAtCol(col) and getDataAtRow(row) to retrieve a row (one line).


2022-09-30 11:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.