postgresql 使用handsontable获取单元格数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30911459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get cell data using handsontable
提问by Erlaunis
I'm looking for insert data in my postgre database from a handsontable data grid. So, I created my grid and it works but now, I don't know how to use methods like "getData" or "getDataAtCell" to get what the user will insert.
我正在我的 postgre 数据库中从一个手动数据网格中寻找插入数据。所以,我创建了我的网格并且它可以工作,但是现在,我不知道如何使用“getData”或“getDataAtCell”之类的方法来获取用户将插入的内容。
Here is the code :
这是代码:
<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>
回答by ZekeDroid
I would probably look at the documentation to figure out how to use those two methods. Essentially, those methods are available to you using the hot
instance so something like hot.getDataAtCell(0,0)
will return to you the data at position 0,0. You could also use hot.getData()
which returns the entire data array.
我可能会查看文档以弄清楚如何使用这两种方法。本质上,这些方法可供您使用hot
实例使用,因此类似的东西hot.getDataAtCell(0,0)
将返回位置 0,0 处的数据。您还可以使用hot.getData()
which 返回整个数据数组。