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
②Modify Data
③Press OK to display alerts
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.
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.
countRows()
and countCols()
to get rows and columns, which are useful.getDataAtCell(row,col)
.getDataAtCol(col)
and getDataAtRow(row)
to retrieve a row (one line).
© 2024 OneMinuteCode. All rights reserved.