【问题标题】:How to use page scroll on ngGridEventScroll?如何在 ngGridEventScroll 上使用页面滚动?
【发布时间】:2015-07-17 13:38:44
【问题描述】:

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

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

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

这将我带到我的第二个问题。我需要通过滚动加载数据,我发现:ngGridEventScroll,但只有在 ngGrid 时触发使用实习生滚动,我需要页面滚动

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

因此,解决方案 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,
    }

可以做什么?

【问题讨论】:

    标签: javascript jquery angularjs ng-grid infinite-scroll


    【解决方案1】:

    您可以使用 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
    

    在您的 html 中

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多