esvit / ng-table

Simple table with sorting and filtering on AngularJS
http://esvit.github.io/ng-table
BSD 3-Clause "New" or "Revised" License
2.77k stars 851 forks source link

table going to first page when data changes #853

Open omgdork opened 8 years ago

omgdork commented 8 years ago

I'm working on a meteor app that uses angular-meteor and ng-table. The dataset of the ng-table is from a collection. You can add rows to the table dynamically via a modal form. The dataset is reactive and changes the view once there's a change in the collection. I'm watching for status changes of the item (QUEUED, PROCESSING, CREATED).

Thing is, if the table is on page 2 and the status changes (any change in the dataset), the table is redrawn and goes back to page 2. Is there a way to make it stay on the current page even with dataset changes?

Here's a sample of what I have so far:

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

The onDatasetChanged event isn't being triggered. I was going to change the page there but I'm not sure if that's a good idea anyway.

anuja-joshi commented 7 years ago

I am Facing same issue, I am continuously streaming data and then updating ng-table data when response comes as:

vm.detailsTable.settings({ data: details });

During this if I go to some 'X' page, and when above statement executes it jumps back to first page. Did anybody find solution for this?