ngGrid sort entire result set

◇◆丶佛笑我妖孽 提交于 2019-12-30 10:17:49

问题


I would like on the ngGridSorted event to sort the entire result set (not just the page) by the sort function that was clicked on. Is there an easy way to do this? I haven't seen a good example of how to sort anything but the page that the user is currently on.


回答1:


In fact you just can use the server-side paging option without actually having serversided code.

The example on the ng-grid demos also just loads a big json file.

The function you need to rewrite is:

 $scope.getPagedDataAsync = function (pageSize, page, searchText)

Instead of loading a file you can put logic in here that has the ability to search and splice an array.

No need to do async stuff just because the function has async in its name.

A library with array manipulation functions like Lo-Dash or Underscore is of great help here.

Update:

Since I found out that the demo doesn't include sorting (Doh!) I made you this Plunker which is an extended version of the official server sided Pagination demo that also features sorting and a non server array.

The code is a bit complex. See if you understand it, or come back with questions.

The sorting Algorithm is not very optimized. In fact I took it from here (Thanks again, David!)



来源:https://stackoverflow.com/questions/25128833/nggrid-sort-entire-result-set

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