0

This is th json, this need to be filtered based on the "testType" equal to 'R' also had to sort based on "createdDate"

{
  "code": null,
  "message": "Total 1 records found",
  "result": {
    "size": 0,
    "dob": 412977600000,
    "sex": "F",
    "visitMasts": [
      {
        "createdBy": 61,
        "visitId": 1235,
        "ordersList": [
          {
            "testId": 4,
            "ordersDto": {
              "orderId": 50815,
              "testType": "R",
              "createdDate": 1479277029456
            }
          },
          {
            "testId": 4,
            "ordersDto": {
              "orderId": 50807,
              "testType": "R",
               "createdDate": 1479016014784
            }
          }
        ]
      }
    ]
  }
}

The filtering is achieved using this,

  vm user = response.data.result;
   if (vm.user.visitMasts[0].ordersList != null && vm.user.visitMasts[0].ordersList.length > 0) {
     radioTestDetails = filterFilter(vm.user.visitMasts[0].ordersList, {
      ordersDto: {
       testType: 'R'
      }
     });
    }

How can I sort the value based on this

response.data.result in that visitMasts -> orderList[] -> createdDate
6
  • Try this (vm.user.visitMasts[0].ordersList.sort(function(l,r){return l.createdDate - r.createdDate}) Commented Nov 17, 2016 at 5:39
  • 1
    You can just use angular's orderBy filter in your controller. First inject $filter into your controller and then just do something like: $filter('orderBy')(radioTestDetails, 'ordersDto. createdDate') to reverse order, just add a third parameter set to true: $filter('orderBy')(radioTestDetails, 'ordersDto. createdDate', true) Commented Nov 17, 2016 at 6:12
  • @StepanKasyanenko (vm.user.visitMasts[0].ordersList.sort(function(l,r){return l.createdDate - r.createdDate}) - creationDate is inside ordersDto , Commented Nov 17, 2016 at 7:44
  • @CrhistianRamirez : Is there any way it will filter with date & time stamp. currently filtering based on date only. Commented Nov 17, 2016 at 8:23
  • 1
    Well, just replace l.createdDate to l.ordersDto.createdDate. Like this vm.user.visitMasts[0].ordersList.sort(function(l,r){return l.ordersDto.createdDate - r.ordersDto.createdDate} Commented Nov 17, 2016 at 9:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.