Sortable table columns with AngularJs

一世执手 提交于 2019-11-30 05:14:15

Updated jsfiddle: http://jsfiddle.net/gweur/

sza is right, you did forget the $scope.sort object, but you are also missing the orderBy filter in your ng-repeat

|orderBy:sort.column:sort.descending

Additionally, you'll need to explicitly pass the column name to the changeSorting() function, like

ng-click="changeSorting('text')"  

not sure if there is a different way you can handle this.

Finally, ng-click is the correct syntax for the version of AngularJS you are using.

Another very good example of making table sortable

http://jsfiddle.net/vojtajina/js64b/14/

<th ng:repeat="(i,th) in head" ng:class="selectedCls(i)" ng:click="changeSorting(i)">{{th}}</th>

scope.changeSorting = function(column) {
    var sort = scope.sort;
    if (sort.column == column) {
        sort.descending = !sort.descending;
    } else {
        sort.column = column;
        sort.descending = false;
    }
};

Here is my solution. I also wrap the whole thing to a directive. The only dependency is UI.Bootstrap.pagination, which did a great job on pagination.

Here is the plunker

Here is the github source code.

Or you can use #ngTasty as simple table directive. github : https://github.com/Zizzamia/ng-tasty docs : http://zizzamia.com/ng-tasty/directive/table

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