使用动手表获取单元格数据

Get cell data using handsontable

本文关键字:单元格 数据 获取 手表      更新时间:2023-09-26

我正在寻找从可动手的数据网格在我的 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() 返回整个数据数组。