Angular Sorting with null objects

前端 未结 4 1180
耶瑟儿~
耶瑟儿~ 2020-12-21 05:39

I need to take records with null values on top , when I\'m sorting by ASC



        
4条回答
  •  萌比男神i
    2020-12-21 06:17

    Create a function in the controller that will receive as parameter the entity and will return either ['team.name','id] either [] or other values that will help push the non-sortable elements to top/bottom of the list.

    EDIT (example)

    HTML:

  • ...
  • AngularJS Ctrl:

    $scope.getItemOrder = function (entity) {
      if (entity.id === null || .... === null) {
        return 0;
      }
    
      return ['team.name','id];
    }
    

提交回复
热议问题