Sorting data in table angular 2

2019-09-12 08:57发布

问题:

How to implemenet sorting data in table with angular 2? With pipe? For example table 5 x 5, click on first cell (on button maybe), and sort all column.

回答1:

The Angular team has advised that you don't use filter pipes in Angular2, as it is an extremely expensive operation.

"The Angular team and many experienced Angular developers strongly recommend that you move filtering and sorting logic into the component itself. The component can expose a filteredHeroes or sortedHeroes property and take control over when and how often to execute the supporting logic. Any capabilities that you would have put in a pipe and shared across the app can be written in a filtering/sorting service and injected into the component."

Now that Angular apps are component based, it is even easier to take this approach when trying to implement any client-side logic that could crush your app's overall performance.

Check out https://angular.io/docs/ts/latest/guide/pipes.html#!#no-filter-pipe for more info.



标签: angular