如何使用角度js中的自定义排序对表进行排序 [英] How do I sort table using custom sort in angular js
本文介绍了如何使用角度js中的自定义排序对表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的桌子
[商店编号] [营业时间] [营业时间] [营业额(%)]
------- -------------------------------------------------- --------------------
1 8--10 100 23
2 9--10 70 15
3 10-- 10 60 8
4 8--8 95 20
5 8--9 70 17
6 9--9 85 19
我能够对数据asc和desc顺序,其中数据是int值,而不是
string中的数据。在这里的示例中,我无法对列[打开关闭时间]进行排序,因为它必须按时间间隔差异排序
。我如何实现这一目标?我需要在所有
列中实现排序功能。休息3列可以根据需要工作。但我不知道如何在
[开始收盘时间]栏中实施排序?
我的HTML
< table>
< thead>
< tr>
< th ng-click =sortRdata('StoreNum')>商店编号< / th>
< th ng-click =sortRdata('OperatingHours')>打开关闭时间< / th>
< th ng-click =sortRdata('AvgCustNum')>打开关闭时间< / th>
< th ng-click =sortRdata('Profit')>利润(%)< / th>
< / tr>
< / thead>
< tbody>
< tr ng-repeat =r in StoreReports | orderBy:sortRcolumn:reverseRsort>
< td> {{:: r.StoreNum}}< / td>
< td> {{:: r.OperatingHours}}< / td>
< td> {{:: r.AvgCustNum}}< / td>
< td> {{:: r.Profit}}< / td>
< / tr>
< / tbody>
< / table>
Javascipt代码:
$ scope.sortRcolumn =StoreNum;
$ scope.reverseRsort = false;
$ scope.sortRdata = function(column){
$ scope.reverseRsort =($ scope.sortRcolumn == column)? !$ scope.reverseRsort:false;
$ scope.sortRcolumn = column;
}
我的尝试:
$ scope.sdata = function(OperatingHours){
var operatingHrArray = operatingHours.slpit('');
var openingHour = parseInt(operatingHrArray [0]);
var closingHour = parseInt(operatingHrArray [3])+ 12;
返回结束时间 - 开放时间;
}
解决方案
scope.sortRcolumn =StoreNum;
< blockquote> scope.reverseRsort = false;
scope.sortRdata = function(column){
My Table [Store Number] [opening closing time] [opening closing time] [Profit (%)] ----------------------------------------------------------------------------- 1 8--10 100 23 2 9--10 70 15 3 10--10 60 8 4 8--8 95 20 5 8--9 70 17 6 9--9 85 19 I am able to sort the data asc and desc order where the data is in int value but not where data in string. Here in example i could not sort the column [opening closing time] as it has to be sort by the time interval difference. How do i achieve this ? I need to implement sort functionality in all column. Rest 3 columns works as desired. But i do not know how do i implement sorting in [opening closing time] column? My HTML <table> <thead> <tr> <th ng-click="sortRdata('StoreNum')">Store Number</th> <th ng-click="sortRdata('OperatingHours')">opening closing time</th> <th ng-click="sortRdata('AvgCustNum')">opening closing time</th> <th ng-click="sortRdata('Profit')">Profit (%)</th> </tr> </thead> <tbody> <tr ng-repeat="r in StoreReports|orderBy:sortRcolumn:reverseRsort "> <td>{{::r.StoreNum}}</td> <td>{{::r.OperatingHours}}</td> <td>{{::r.AvgCustNum}}</td> <td>{{::r.Profit}}</td> </tr> </tbody> </table> Javascipt Code: $scope.sortRcolumn = "StoreNum"; $scope.reverseRsort = false; $scope.sortRdata = function (column) { $scope.reverseRsort = ($scope.sortRcolumn == column) ? !$scope.reverseRsort : false; $scope.sortRcolumn = column; }
What I have tried:
$scope.sdata = function (OperatingHours) { var operatingHrArray = operatingHours.slpit(''); var openingHour = parseInt(operatingHrArray[0]); var closingHour = parseInt(operatingHrArray[3]) + 12; return closingHour - openingHour; }
解决方案
scope.sortRcolumn = "StoreNum";
scope.reverseRsort = false;
scope.sortRdata = function (column) {
这篇关于如何使用角度js中的自定义排序对表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文