简体   繁体   English

如何在无限滚动中显示仅排序的25个元素?

[英]how to display sorted only 25 element in infinite scroll?

I am using infinite scroll in my demo ,In which I am showing only 25 element first time .When user scroll down to bottom it load more data and display that more data .It is do repeat steps if user want whole data to display (scroll to bottom load more data).but in my demo there is ascending and descending functionality present .On header there is "V" and "^" Button present .using click of that button I need to ascend and descend data .In my demo it is working fine .But the issue is when user click it load all data but I want it show only 25 data (ascending and descending.) 我在演示中使用了无限滚动,其中第一次仅显示25个元素。当用户向下滚动到底部时,它将加载更多数据并显示更多数据。如果用户希望显示整个数据,请重复执行这些步骤(滚动底部加载更多数据)。但是在我的演示中,存在升序和降序功能。在标题上存在“ V”和“ ^”按钮。单击该按钮,我需要进行升序和降序数据。在我的演示中工作正常。但是问题是当用户单击它加载所有数据但我只希望它显示25个数据(升序和降序)时。

I will explain more . 我会解释更多。

  • When you run app it show only 25 elements in table if user want to see more it scroll the table it load more data when it move to bottom. 当您运行应用程序时,如果用户希望查看更多内容,则它仅在表格中显示25个元素,它会滚动表格,并在移至底部时加载更多数据。
  • when user Click header left icon ( Account )"V" and "^" Account .It sorted all the object and display it in screen .All object mean it show 2000 objects in sorted way . 当用户单击标题左图标( 帐户 )“ V”和“ ^” 帐户时 ,对所有对象进行排序并在屏幕上显示。所有对象表示按排序方式显示2000个对象。
  • So the issue is when user click header left icon ( Account )"V" and "^" I want to display only 25 element of sorted array and load data when user scroll to bottom . 所以问题是,当用户单击标题左图标( 帐户 )“ V”和“ ^”时,我只想显示25个排序数组的元素,并在用户滚动到底部时加载数据。

HTML 的HTML

<ion-scroll scrollbar-y="true" ng-style="backGroundImageHeightObj" delegate-handle="invoicegrid">
          <div class="row" ng-repeat="column in invoice_records | orderBy: sortval: reverse track by $index">
            <div class="col col-center brd collapse-sm" ng-repeat="field in column.columns" ng-show="data[$index].checked && data[$index].fieldNameOrPath===field.fieldNameOrPath">{{field.value}}</div>
            <div class="col col-10 text-center brd collapse-sm"></div>
          </div>
        </ion-scroll>
        <ion-infinite-scroll immediate-check="false" ng-if="!noMoreItemsAvailable" on-infinite="loadMore(query)" distance="10%"></ion-infinite-scroll>

In the ShowViewAfterSuccess function you slice all invoice records to get just the ones to be displayed: ShowViewAfterSuccess函数中,您可以对所有发票记录进行切片以仅获取要显示的记录:

$scope.invoice_records = $scope.total_invoice_records.slice(0, showitems);

Then, in the setSort function you clear the invoice_records list and then set it with the whole list of invoice records (without slicing the first 25): 然后,在setSort函数中,清除invoice_records列表,然后将其与整个发票记录列表一起设置(不对前25个切片进行切片):

$scope.invoice_records=$scope.total_invoice_records;

That's why you get the whole list upon re-sorting. 这就是为什么您在重新排序时会得到整个列表。

Ideally, you'd want to get sorted data from the back-end in batches to feed the infinite scroll. 理想情况下,您希望从后端分批获取排序的数据以馈入无限滚动。 Assuming you cannot do that, you can use the limitTo filter to control how many lines are displayed in the ngRepeat. 假设您无法执行此操作,则可以使用limitTo过滤器来控制ngRepeat中显示多少行。 Also, in your setSort you may want to scroll back to the top. 另外,在setSort您可能需要滚动回到顶部。

Here's an updated Plunker . 这是更新的Plunker

Main changes are: 主要变化是:

  • Added limitTo: counter to the main ngRepeat: 增加了limitTo:与主要ngRepeat的计数器:

ng-repeat="column in total_invoice_records | orderBy: sortval: reverse | limitTo: counter track by $index"

  • Made counter a scope variable 计数器范围变量

  • Made sure $scope.invoice_records always contains all records by removing all slicing. 通过删除所有切片,确保$scope.invoice_records始终包含所有记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM