使用 nghandsontable 访问 handsontable methods/properties
Access handsontable methods/properties using nghandsontable
我正在使用 ngHandsontable Angular directive for Handsontable。我成功地显示了数据,但我很难访问修改后的行,因此我无法将数据发送到数据库。
我尝试绑定 afterChange 回调,但索引似乎在列排序后关闭。 (显示 table 上显示的行的索引,不在数据源中)
我想知道保存 ngHandsontable 数据的最佳做法是什么,或者我应该如何访问 API 方法或 columnSorting 属性
非常感谢您的帮助!
- 马可
我最终使用 afterInit 事件获取实例,然后在 afterChange 等其他事件中调用方法。
我的代码是这样的:
afterInit: function() {
$scope.hot.instance = this;
}
然后:
afterChange: function (changes, source) {
if (source != 'loadData') {
var hot = $scope.hot.instance;
var dataRow = hot.getSourceDataAtRow(index)
// .... saveChanges...
};
}
非常感谢 Bricktop 给我的提示。
我就是按照这样的逻辑解决的:
post: function postLink(scope, iElement, iAttrs, controller) {
var hotDiv = iElement.find("div[hot-table]")
var hotInstance = hotDiv.isolateScope().hotInstance;
hotInstance.addHook('afterLoadData', function(){
console.log("loaded data");
});
}
只需在控制器中使用视图模型
var vm = this;
然后您可以调用此视图模型的任何核心可操作方法,例如
this.getCell()
this.getSourceDataAtRow()
我正在使用 ngHandsontable Angular directive for Handsontable。我成功地显示了数据,但我很难访问修改后的行,因此我无法将数据发送到数据库。
我尝试绑定 afterChange 回调,但索引似乎在列排序后关闭。 (显示 table 上显示的行的索引,不在数据源中)
我想知道保存 ngHandsontable 数据的最佳做法是什么,或者我应该如何访问 API 方法或 columnSorting 属性
非常感谢您的帮助! - 马可
我最终使用 afterInit 事件获取实例,然后在 afterChange 等其他事件中调用方法。
我的代码是这样的:
afterInit: function() {
$scope.hot.instance = this;
}
然后:
afterChange: function (changes, source) {
if (source != 'loadData') {
var hot = $scope.hot.instance;
var dataRow = hot.getSourceDataAtRow(index)
// .... saveChanges...
};
}
非常感谢 Bricktop 给我的提示。
我就是按照这样的逻辑解决的:
post: function postLink(scope, iElement, iAttrs, controller) {
var hotDiv = iElement.find("div[hot-table]")
var hotInstance = hotDiv.isolateScope().hotInstance;
hotInstance.addHook('afterLoadData', function(){
console.log("loaded data");
});
}
只需在控制器中使用视图模型
var vm = this;
然后您可以调用此视图模型的任何核心可操作方法,例如
this.getCell()
this.getSourceDataAtRow()