本文介绍了NG-表格排序不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经用NG-表,采用了NG-表生成表的应用程序,该应用程序工作正常。我现在面临的问题是,该表的排序是行不通的。我的code为如下
给出
HTML
<表NG表=tableParams级=表>
< TR NG重复=用户myValues>
< TD数据标题='名'排序='名'>
{{用户名}}
< / TD>
< TD数据标题='时代'排序='年龄'>
{{user.age}}
< / TD>
< / TR>
< /表>
脚本
VAR应用= angular.module('主',['ngTable'])。
控制器('DemoCtrl',函数($范围,$过滤器,ngTableParams){
$ scope.myValues = [{名:莫罗尼,年龄:50},
{名:Tiancum,年龄:43},
{名:雅各布,年龄:27},
{名:尼,年龄:29},
{名:挪,年龄:34},
{名:Tiancum,年龄:43},
{名:雅各布,年龄:27},
{名:尼,年龄:29},
{名:挪,年龄:34},
{名:Tiancum,年龄:43},
{名:雅各布,年龄:27},
{名:尼,年龄:29},
{名:挪,年龄:34},
{名:Tiancum,年龄:43},
{名:雅各布,年龄:27},
{名:尼,年龄:29},
{名:挪,年龄:34}]; $ scope.tableParams =新ngTableParams({
排序:{
名称:ASC
}
},{
的getData:函数($延迟,则params){
$ defer.resolve($滤波器('ORDERBY')($ scope.myValues,params.orderBy()));
}
});
});
解决方案
$ defer.resolve($过滤器('排序依据')($ scope.myValues,params.orderBy()) );
将创建一个新的有序数组,但不会改变 $ scope.myValues
。
因此,无论你设置 $ scope.myValues
每次排序数组:
$ scope.myValues = $过滤器('排序依据')($ scope.myValues,params.orderBy());
$ defer.resolve($ scope.myValues);
或者使用 $数据
在 NG-重复
而不是 myValues
:
< TR NG重复=用户$ DATA>
I have created an application using ng-table, the application is working fine which had generated table using ng-table. The problem which i am facing is that the table sorting is not working. My code is as given below
html
<table ng-table="tableParams" class="table">
<tr ng-repeat="user in myValues">
<td data-title="'Name'" sortable="'name'">
{{user.name}}
</td>
<td data-title="'Age'" sortable="'age'">
{{user.age}}
</td>
</tr>
</table>
script
var app = angular.module('main', ['ngTable']).
controller('DemoCtrl', function($scope, $filter, ngTableParams) {
$scope.myValues = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];
$scope.tableParams = new ngTableParams({
sorting: {
name: 'asc'
}
}, {
getData: function($defer, params) {
$defer.resolve($filter('orderBy')($scope.myValues, params.orderBy()));
}
});
});
解决方案
$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-repeat
instead of myValues
:
<tr ng-repeat="user in $data">
这篇关于NG-表格排序不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!