Handsontable Dynamically Set Settings

心不动则不痛 提交于 2019-12-13 15:44:10

问题


I have a very big handsontable. I have dropdown columns defined, but, the values for the sources are retrieved with AJAX.

How can I set the "source" property of a "column" of type "dropdown" dynamically?

Regards!


回答1:


You can, and should, use:

hotInstance.updateSettings({
  columns: getNewColumns()
})

Where getNewColumns() would return an array of columns with the data and new source (or make the AJAX call from in here). That should do it!




回答2:


Thank you for the answer ZekeDroid.

I was able to solve my issue.

First lets talk about a problem in the angular directive: I am using the handsontable's angular directive. Two things happen: 1. If I associated the datarows attribute to a nested variale in the model, for example $scope.hot.data, then when I change the value of the model ( $scope.hot.data ) the grid ui is not refreshed. I am pretty sure this is an issue with the directive. Now: 2. Assume I use $scope.data and I update its value (this is the model right), then the grid ui is not refreshed either. I have to do something like hotInstance.updateSettings({data: newData}) as well.

I have to do both things; that is, update the model and call the update settings method. This is the only way I could get it work properly.

Note: if I do $scope.$apply() instead the updateSettings, I get an error in the console.



来源:https://stackoverflow.com/questions/28617551/handsontable-dynamically-set-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!