我想在每个列中包含不同数据类型的表头中添加排序功能,所以我做了类似这样的事情:
<thead>
<tr>
<th ng-click="sortItems('stringCol')">Name</th>
<th ng-click="sortItems('dateCol')">Date Col</th>
<th ng-click="sortItems('numCol')">Number Col</th>
<th ng-click="sortItems('currencyCol')">Currency Col</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items | orderBy:sortColumn:reverseSort">
<td>{{item.stringCol}}</td>
<td>{{item.dateCol}}</td>
<td>{{item.numCol}}</td>
<td>{{item.currencyCol}}</td>
</tr>
</tbody>
这是js:
$scope.sortColumn = "stringCol";
$scope.reverseSort = false;
$scope.sortData = function(column){
$scope.reverseSort = ($scope.sortColumn == column) ? !$scope.reverseSort : false;
$scope.sortColumn = column;
};
它将所有数据视为字符串,因此对于非字符串列不能正常工作。此外,每列也可以具有空值。 我是角度js的新手,我知道我需要一个自定义过滤功能,但我不知道怎么做。任何帮助,将不胜感激。