如何在ngGridEventScroll上使用页面滚动?

non*_*ipt 6 javascript jquery infinite-scroll angularjs ng-grid

使用ngGrid v2.X,我试图在页面滚动(不是网格滚动)到底时开发一个加载更多数据的网格.

通过搜索类似的问题,我找到了第一个问题的解决方案: ngGrid必须有动态高度,所以我做了这个

.ngViewport{ height:auto !important; } .ngCanvas, .ngViewport, .ngRow, .ngFooterPanel, .ngTopPanel { width: 100% !important; } .ngRow { border-bottom:none !important; }
Run Code Online (Sandbox Code Playgroud)

这让我想到了第二个问题.我需要通过滚动加载数据,我发现:ngGridEventScroll,但是当使用ngGrid实习生滚动时,我只需触发,我需要页面滚动

  $scope.$on('ngGridEventScroll', function () {
        $scope.currentDataPosition++;
        $scope.setPagingData($scope.dataArray, $scope.currentDataPosition, $scope.pagingOptions.pageSize);
    });
Run Code Online (Sandbox Code Playgroud)

因此,解决方案1打破了解决方案2,因为ngGridEventScroll不再具有实习生滚动.

 $scope.setPagingData = function (data, page, pageSize) {
        cfpLoadingBar.start();
        var pagedData = data.slice((page - 1) * pageSize, page * pageSize, page * pageSize);
        $scope.totalServerItems = data.length;
        $scope.myData = pagedData;
        cfpLoadingBar.complete();
    };

 $scope.gridOptions = {
        data: 'myData',
        virtualizationThreshold: 50,
        enableRowSelection: false,
        enablePaging: false,
        enableSorting: false,
        showFooter: false,
        pagingOptions: $scope.pagingOptions,
        filterOptions: $scope.filterOptions,
    }
Run Code Online (Sandbox Code Playgroud)

可以做些什么?

Ant*_*ant 0

您可以使用 ngInfiniteScroll ( https://sroze.github.io/ngInfiniteScroll/index.html ) 并应用以下策略。

在你的控制器中

    $scope.limit = 50; // Initial limit (make sure its enough to cover the whole page, otherwise the raiseLimit function might not be called)
    $scope.raiseLimit = function() { // function called by ngInfiniteScroll
         if ( $scope.limit < data.length) {
             $scope.limit += 10; // adjust to your need
         } else {
             $scope.dataLoaded = true;
         }
    }
    $scope.dataLoaded = false; // prevent useless call
    $scope.myData = $filter('limitTo')(data, $scope.limit); // Do not forget to inject $filter into your controller
Run Code Online (Sandbox Code Playgroud)

在你的html中

    <div infinite-scroll='raiseLimit()' infinite-scroll-disabled='dataLoaded'>
        <!-- put your grid with dynamic height here -->
    </div>
Run Code Online (Sandbox Code Playgroud)