ng-table在数据更改时转到第一页

时间:2016-05-18 10:37:12

标签: angularjs meteor ngtable angular-meteor

我正在研究使用角度流星和ng-table的流星应用程序。 ng表的数据集来自集合。您可以通过模式窗体动态地向表中添加行。数据集是被动的,一旦集合发生变化,就会更改视图。我正在关注该项目的状态更改(QUEUEDPROCESSINGCREATED)。

事情是,如果表位于第2页并且状态发生变化(数据集中的任何更改),表格将重新绘制并返回到第2页。有没有办法让它保持在当前页面上,即使数据集更改?

以下是我目前的样本:

(function () {
    'use strict';

    function myController($scope, $reactive, ngTableParams, ngTableEventsChannel, myService) {
        $reactive(this).attach($scope);

        this.subscribe('myCollection');

        this.currentPage = 1;
        this.helpers({
            tableParams: () => {
                return new ngTableParams({
                    page: this.currentPage
                }, {
                    //this is just a simple collection call
                    dataset: myService.getItems().fetch()
                });
            }
        });

        $scope.$watch('vm.tableParams', (params) => {
            //not triggered :(
            ngTableEventsChannel.onDatasetChanged(() => {
                console.log('data changed');
                tableParams.page($scope.currentPage);
            }, $scope, tableParams);

            ngTableEventsChannel.onPagesChanged(() => {
                $scope.currentPage = tableParams.page();
            }, $scope, tableParams);
        });
    }

    angular.module('MyApp').controller('MyController', myController);
})();

未触发onDatasetChanged事件。我打算在那里更改页面,但我不确定这是不是一个好主意。

0 个答案:

没有答案