最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Get cell data using handsontable - Stack Overflow

matteradmin2PV0评论

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
Add a ment  | 

1 Answer 1

Reset to default 9

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.

Post a comment

comment list (0)

  1. No comments so far