Refresh a handsontable

Erlaunis picture Erlaunis · Jul 29, 2015 · Viewed 22.3k times · Source

I want to refresh a handsontable grid. I have some columns with a dropdown filled with data of my database. But in my page, I have a first grid which insert data in this database and I get them in my second grid. But as my second grid is not refresh, I can't get the last value I just insert in the first grid.

So how can I refresh the content of a handsontable please ?

EDIT :

I made a jsfiddle which illustrate my problem : http://jsfiddle.net/9onuhpn7/10/ On my jsFiddle, it works and I can get the values when I push them in the array. But with my real application, and with a database, it doesn't work.

So instead of an array, I have this in my code (it works but it's not refreshed) :

columns:[
<?php 

    $conn_string = "host=localhost port=5432 dbname=test_postgre user=postgres password='1234'";
    $dbconn = pg_connect($conn_string);

    $sql = "SELECT ".$colonne." FROM public.".$tablevar."";
    $res = pg_query($sql) or die("Pb avec la requete: $sql");

    $data = pg_fetch_all($res);

    $indexedOnly = array();

    foreach ($data as $row) {
                $indexedOnly[] = array_values($row);
    }
    echo '{type:\'dropdown\',';
    echo 'source:'.json_encode($indexedOnly).'},';



?>]

Answer

Shimmy Weitzhandler picture Shimmy Weitzhandler · Dec 31, 2015

Just call hot.render();, where hot refers to the Handsontable object.

Worked great for me.