Yogiraj Havinal
Yogiraj Havinal

Reputation: 13

Sorting In AngularJS

self.records: [
  {
    "Reg_code": 10001025,
    "Name": "Chandan Kumar Penta",
    "staticColumn": {
      "Check": "Check1",
      "HHHHH": ""
    }
  },
  {
    "Reg_code": 10001290,
    "Name": "test_B2 ",
    "staticColumn": {
      "Check": "Check2",
      "HHHHH": ""
    }
  },
  {
    "Reg_code": 10001028,
    "Name": "Ronny Lewis",
    "staticColumn": {
      "Check": "Check3",
      "HHHHH": ""
    }
  }
]

This is my JSON object. I want to sort on the basis on Check in AngularJS. Please help.

Upvotes: 0

Views: 53

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222552

You can do,

<div class="adaptions" ng-repeat="record in records | orderBy:'staticColumn.Check' ">

DEMO

var app = angular.module('todoApp', []);

app.controller("dobController", ["$scope",
  function($scope) {
    $scope.records  = [
  {
    "Reg_code": 10001025,
    "Name": "Chandan Kumar Penta",
    "staticColumn": {
      "Check": "Check4",
      "HHHHH": ""
    }
  },
  {
    "Reg_code": 10001290,
    "Name": "test_B2 ",
    "staticColumn": {
      "Check": "Check2",
      "HHHHH": ""
    }
  },
  {
    "Reg_code": 10001028,
    "Name": "Ronny Lewis",
    "staticColumn": {
      "Check": "Check3",
      "HHHHH": ""
    }
  }
];
   
  
  }
]);
<!DOCTYPE html>
<html ng-app="todoApp">

<head>
  <title>Sample</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
</head>
<body ng-controller="dobController">
 <div class="adaptions" ng-repeat="record in records | orderBy:'staticColumn.Check' ">
     <ul>
       <li >{{ record.staticColumn.Check }}</li>
    </ul>
</div>
 
</body>

</html>

Upvotes: 3

Related Questions