简体   繁体   中英

Get cell data using handsontable

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM