Angularjs : sorting shows different result in chro

2019-05-05 10:01发布

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

Fire Fox Result

Chrome Result : Rank Column shows Rank with Hashkey value

Chrom Result

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条回答
狗以群分
2楼-- · 2019-05-05 10:42

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]);
        }
查看更多
登录 后发表回答