Access handsontable methods/properties using nghandsontable

为君一笑 提交于 2019-12-10 14:15:21

问题


I'm using ngHandsontable Angular directive for Handsontable. I managed to show the data successfully, but I'm struggling with getting access to the modified rows so I can send the data to the DB.
I tried binding the afterChange callback, but the index seems to be off after column sorting. (shows the index of the row shown on the table, not in the dataSource)

I wonder what's the best practice to save ngHandsontable data or what I should do to access the API like getData method or columnSorting property

Thanks a lot for your help! - Marco


回答1:


I ended up using afterInit event to get the instance and then call the methods in further events like the afterChange.

This is how my code looks like:

afterInit: function() {
        $scope.hot.instance = this;
    }

and then:

afterChange: function (changes, source) {
        if (source != 'loadData') {          
            var hot = $scope.hot.instance;
            var dataRow = hot.getSourceDataAtRow(index)
            // .... saveChanges...
        };
    }

Thanks a lot to Bricktop for giving me the hint.




回答2:


I just solved it with this sort of logic:

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");
    });
}



回答3:


Simply use view model in the controller

var vm = this;

and then you can call any of the core handsontable method of this view model like

this.getCell()

this.getSourceDataAtRow()


来源:https://stackoverflow.com/questions/28330340/access-handsontable-methods-properties-using-nghandsontable

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