我正在从可操作的数据网格中寻找在我的 postgre 数据库中插入的数据。所以,我创建了我的网格并且它可以工作但是现在,我不知道如何使用“getData”或“getDataAtCell”之类的方法来获取用户将插入的内容。
代码如下:
<div id="example" class="excel"></div>
<script>
var data = [
["LastName", "FirstName", "Age", "Height"],
["", "","" ,"" ]
];
var container = document.getElementById('example');
var hot = new Handsontable(container, {
data: data,
minSpareRows: 1,
rowHeaders: true,
colHeaders: false,
contextMenu: true
});
</script>
<!-- <a href="#" id="valider">Submit</a>-->
<button type="button" class="btn btn-default" id="submit_button">Submit</button>
<script>
$(document).ready(function(){
$('#submit_button').click(function(){
//alert ("test");
//getDataAtCell(1,1);
<?php
//$conn_string = "host=localhost port=5432 dbname=ita2015 user=postgres password='1234'";
//$dbconn = pg_connect($conn_string);
//$sql = "INSERT INTO test_perso.etudiant(id_etudiant, nom_etudiant)
// VALUES('5', ".data[1][0].");";
//$res = pg_query($sql) or die("Pb avec la requete: $sql");
//echo data[0][0];
?>
var temp;
temp = $("#example").handsontable('getCell', 0, 0);
alert(temp);
});
});
</script>
最佳答案
我可能会查看文档以了解如何使用这两种方法。本质上,您可以使用 hot
实例使用这些方法,因此类似 hot.getDataAtCell(0,0)
的方法将返回位置 0,0 处的数据。您还可以使用返回整个数据数组的 hot.getData()
。
关于javascript - 使用 handsontable 获取单元格数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30911459/