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.
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>
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.
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>
Share
Improve this question
asked Jun 18, 2015 at 9:25
ErlaunisErlaunis
1,4516 gold badges33 silver badges50 bronze badges
1 Answer
Reset to default 9I 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.