javascript 刷新手持台
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31702262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refresh a handsontable
提问by Erlaunis
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 ?
那么我该如何刷新handsontable的内容呢?
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.
我做了一个 jsfiddle 来说明我的问题:http: //jsfiddle.net/9onuhpn7/10/在我的 jsFiddle 上,它可以工作,当我将它们推入数组时,我可以获得这些值。但是对于我的真实应用程序和数据库,它不起作用。
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).'},';
?>]
回答by Shimmy Weitzhandler
Just call hot.render();
, where hot
refers to the Handsontable
object.
只需调用hot.render();
, wherehot
指的是Handsontable
对象。
Worked great for me.
对我很有用。
回答by ZekeDroid
I get it now. You want to dynamically update sources for dropdowns. That should be easy with the following code:
我现在明白了。您想动态更新下拉菜单的来源。使用以下代码应该很容易:
hot2.updateSettings({
columns: [{
type: 'dropdown',
source: arrayTest
}]
})
Make sure to add this after arrayTest
has the new values and you should be set to go. Here's your fiddlewith the line added in the right place.
确保在arrayTest
拥有新值之后添加它,你应该准备好去。这是您在正确位置添加的行的小提琴。
回答by mpusarla
Try setting the observeChanges option to true. This should detect the changes in the data source and render the grid again.
尝试将observeChanges 选项设置为true。这应该检测数据源中的更改并再次渲染网格。
https://github.com/handsontable/handsontable/wiki/Options#constructor-options
https://github.com/handsontable/handsontable/wiki/Options#constructor-options
回答by dasfdsa
Accepted answer didn't work for me, but following code worked fine.
接受的答案对我不起作用,但以下代码工作正常。
let hot = new Handsontable(this.hotTableComponentTest.nativeElement, {
data: [["","",""]] ,
...
});
if (value && value.length>0 && this.hot) {
this.hot.getInstance().loadData(value);
this.hot.getInstance().render();
}