AngularJS sorting rows by table header

后端 未结 9 1930
旧巷少年郎
旧巷少年郎 2020-12-04 07:08

I have four table headers:

$scope.headers = [\"Header1\", \"Header2\", \"Header3\", \"Header4\"];

And I want to be able to sort my table by

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 07:59

    I'm just getting my feet wet with angular, but I found this great tutorial.
    Here's a working plunk I put together with credit to Scott Allen and the above tutorial. Click search to display the sortable table.

    For each column header you need to make it clickable - ng-click on a link will work. This will set the sortName of the column to sort.

    
         
              
              
               Name
         
    
    

    Then, in the table body you can pipe in that sortName in the orderBy filter orderBy:sortName:sortReverse

    
         {{repo.name}}
         {{repo.stargazers_count | number}}
         {{repo.language}}
    
    

提交回复
热议问题