Angularjs : sorting shows different result in chrome and firefox browser

折月煮酒 提交于 2019-12-22 08:18:00

问题


HI I am getting different result in chrome and firefox browser of sorting of data. Firefox shows correct one.

HTML :

<table class="datatable">
              <thead>
                <tr>
                  <th width="5%" class="Rank">Rank&nbsp;<a ng-click="sort_by('Rank')"><i class="icon-sort" ng-show="pagedItems[currentPage].length > 1"></i></a></th>
                  <th width="10%" class="Interviews">Interviews&nbsp;<a ng-click="sort_by('Interviews')"><i class="icon-sort" ng-show="pagedItems[currentPage].length > 1"></i></a></th>
                  <th width="25%" class="Dealership">Dealership&nbsp;<a ng-click="sort_by('Dealership')"><i class="icon-sort" ng-show="pagedItems[currentPage].length > 1"></i></a></th>
                  <th width="15%" class="Satisfaction">Overall Satisfaction&nbsp;<a ng-click="sort_by('Satisfaction')"><i class="icon-sort" ng-show="pagedItems[currentPage].length > 1"></i></a></th>
                  <th width="15%" class="Loyalty">Loyalty&nbsp;<a ng-click="sort_by('Loyalty')"><i class="icon-sort" ng-show="pagedItems[currentPage].length > 1"></i></a></th>
                </tr>
              </thead>
              <tbody>
                <tr ng-repeat="item in pagedItems[currentPage] | orderBy:sortingOrder:reverse">
                    <td>{{item.Rank}} - {{item.$$hashKey}}</td>
                    <td>{{item.Interviews}}</td>
                    <td>{{item.Dealership}}</td>
                    <td>{{item.Satisfaction | number:1}}</td>
                    <td>{{item.Loyalty}}</td>
                </tr>
            </tbody>

I am sorting initially with Rank :

Angular Controller Code :

$scope.sortingOrder = sortingOrder;
$scope.reverse = false;

Result in Firefox : Rank Column shows Rank with Hashkey value

Chrome Result : Rank Column shows Rank with Hashkey value

Here I am sorting with Rank. The Data with Same Rank gets sorted after their $$hashkey. Firefox gives $$hashkey in order it gets data. where as Chrome palce the second record to last in giving hash key.

I am not able to understand why this is happening. is there any way i can avoid.

Thanks in advance.


回答1:


I had the same problem in Google Chrome. The remedy was to set the initial sort field upon page load.

I was not doing that previously:

$scope.items = {[$data]}    



        $scope.mySortFunction = function(item) {
            if(isNaN(item[$scope.sortExpression]))
                return item[$scope.sortExpression];
            return parseInt(item[$scope.sortExpression]);
        }

I changed the above to this:

$scope.items = {[$data]}    

        //we want the 1st load to be sorted by sort_code
        $scope.sortExpression = 'sort_code';

        $scope.mySortFunction = function(item) {
            if(isNaN(item[$scope.sortExpression]))
                return item[$scope.sortExpression];
            return parseInt(item[$scope.sortExpression]);
        }


来源:https://stackoverflow.com/questions/22651220/angularjs-sorting-shows-different-result-in-chrome-and-firefox-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!