<div>
<table ng-table="vm.tableParams" class="table table-condensed table-bordered table-striped">
<tr ng-repeat="row in $data">
<td data-title="'商品名'" filter="{iname: 'text'}" sortable="'iname'">{{row.iname}}</td>
<td data-title="'库存数'" filter="{inums: 'number'}" sortable="'inums'">{{row.inums}}</td>
<td data-title="'售价'" filter="{iprice: 'number'}" sortable="'iprice'">{{row.iprice}}</td>
</tr>
</table>
</div>
如图所示,库存数排序,明显不正确;求解
inums 是从json得到的字符串型;
inums:"30"
用orderby这个angular自带的filter即可
样例:
<div ng-controller="ExampleController">
<table class="friends">
<tr>
<th>Name</th>
<th>Phone Number</th>
<th>Age</th>
</tr>
<tr ng-repeat="friend in friends | orderBy:foo">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
<td>{{friend.age}}</td>
</tr>
</table>
</div>
然后你想改变排序规则的时候,改$scope.foo
的值就可以了。比如$scope.foo
的值可以是"age"
(注意引号),然后angular就会自动依照age的值进行排序了。
建议去看一下官方的文档
看看 angular $filter orderby