我正在尝试使用angularjs ng-table对表进行排序,但是我无法做到这一点。下面是我用于排序的代码。
var sortKey = $scope.fieldName;
$scope.releasedTable = new ngTableParams({
page : 1,
count : $scope.defaultpageSize,
sorting : {
sortKey : 'desc'
}
});
如果我传递上面的sortKey这样的动态变量,它就无法正常工作。但是我的下面代码是有效的,因为它中包含静态变量fName。
$scope.releasedTable = new ngTableParams({
page : 1,
count : $scope.defaultpageSize,
sorting : {
fName : 'desc'
}
});
html:
<table id="action-pending-table" ng-table="releasedTable" class="table table-striped">
<thead>
<tr>
<th ng-repeat="column in columns"
ng-class="{'sort-asc': releasedTable.isSortBy(column.fieldName, 'asc'),
'sort-desc': releasedTable.isSortBy(column.fieldName, 'desc')}"
ng-click="releasedTable.sorting(column.fieldName, releasedTable.isSortBy(column.fieldName, 'asc') ? 'desc' : 'asc'); changeIcon(icon)" ng-if="column.display"> {{column.displayName}}
<icon-change icon="icon"></icon-change></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="record in records">
<td ng-repeat="column in columns">
<span ng-if="isNeededLink(column.fieldName)">>{{record[column.fieldName]}} </span></td>
</tr>
</tbody>
</table>
请建议我该如何解决此问题。