Как отсортировать таблицу с помощью пользовательской сортировки в angular js
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; }
Что я уже пробовал:
$scope.sdata = function (OperatingHours) { var operatingHrArray = operatingHours.slpit(''); var openingHour = parseInt(operatingHrArray[0]); var closingHour = parseInt(operatingHrArray[3]) + 12; return closingHour - openingHour; }