How to use page scroll on ngGridEventScroll?

夙愿已清 提交于 2019-12-12 10:46:28

问题


Using ngGrid v2.X, I'm trying to devolop a grid that loads more data when page scroll (not grid scroll) goes bottom.

By searching for similar questions i've found a solution to my 1st problem: ngGrid must have dynamic height, so i've did this

.ngViewport{ height:auto !important; } .ngCanvas, .ngViewport, .ngRow, .ngFooterPanel, .ngTopPanel { width: 100% !important; } .ngRow { border-bottom:none !important; }

Which takes me to my 2nd problem. I need data be loading by scroll, and i've found: ngGridEventScroll, but only triggers when ngGrid intern scroll is used, i need page scroll

  $scope.$on('ngGridEventScroll', function () {
        $scope.currentDataPosition++;
        $scope.setPagingData($scope.dataArray, $scope.currentDataPosition, $scope.pagingOptions.pageSize);
    });

So, solution 1, breaks the solution 2, because ngGridEventScroll doesnt have the intern scroll anymore.

 $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,
    }

What could be done ?


回答1:


You could use ngInfiniteScroll (https://sroze.github.io/ngInfiniteScroll/index.html) and apply the following strategy.

In your controller

    $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

In your html

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


来源:https://stackoverflow.com/questions/31477188/how-to-use-page-scroll-on-nggrideventscroll

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