ng-table sorting not working

只谈情不闲聊 提交于 2019-12-04 04:58:49
$defer.resolve($filter('orderBy')($scope.myValues, params.orderBy()));

will create a new sorted array but will not change $scope.myValues.

So either, you set $scope.myValues to the sorted array each time:

$scope.myValues = $filter('orderBy')($scope.myValues, params.orderBy());
$defer.resolve($scope.myValues);

Or use $data in ng-repeatinstead of myValues:

<tr ng-repeat="user in $data">

In your HTML you need to update the myValues to be $data.

<tr ng-repeat="user in $data">

Plunker

You're writing to $scope.myValues, and using that in the ng-repeat directive - but you're sorting the data only in getData() on the table params object.

getData() doesn't ever change $scope.myValues, it only uses it to return a sorted array. What you really want to do is:

  • Don't make the full dataset available on the scope, but store it in a variable inside the controller:

var data = [{name: "Moroni", age: 50}, ...]

$defer.resolve($filter('orderBy')(data, params.orderBy()));

  • Use $data inside the HTML code, because this is what accesses getData():

<tr ng-repeat="user in $data">

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