nipiv
nipiv

Reputation: 843

Angularjs filter with nested json

I have having trouble with filtering my table with the below json object. It filters some of the key values, but doesnt work if my json is nested. I am sure i am doing something wrong and stupid.

heres a fiddle of the same. https://jsfiddle.net/pnypxhj8/1/

below is my JSON object:

[
 {
    "EmpId": "3901",   //----> Filter works on this
    "SubmitDate": "30/04/2017", //----> Filter works on this
    "Employee": "John", //----> Filter works on this
    "ProdRequest": [{
            "ProdName": "Mac Air laptop - Apple",
            "ManagersApproval": {
                "Status": "Approved",  //----> But Doesnt works on this
                "ManagersDetails": [{
                        "Name": "Steve Rock",
                        "Email": "[email protected]"
                    },
                    {
                        "Name": "Mary Nuts",
                        "Email": "[email protected]"
                    }
                ],
                "Comments": ""
            },
            "AdminApproval": {
                "Status": "Pending",
                "AdminDetails": [{
                        "Name": "Hardy Lee",
                        "Email": "[email protected]"
                    },
                    {
                        "Name": "Moss Grant",
                        "Email": "[email protected]"
                    }
                ],
                "Comments": ""
            },
            "RequestStatus": "Pending"
        },
        {
            "ProdName": "Note Book - Large",
            "ManagerApproval": {
                "Status": "Approved",
                "Approver": [{
                    "Name": "Jet Lee",
                    "Email": "[email protected]"
                }],
                "Comments": "Approved by Jet Lee"
            },

            "AdminApproval": {
                "Status": "Approved",
                "AdminDetails": [{
                        "Name": "Hardy Lee",
                        "Email": "[email protected]"
                    },
                    {
                        "Name": "Moss Grant",
                        "Email": "[email protected]"
                    }
                ],
                "Comments": ""
            },
            "RequestStatus": "Completed"
        }
    ]
},
{
    "EmpId": "550",
    "SubmitDate": "22/04/2017",
    "Employee": "Mary Kom",
    "ProdRequest": [{
            "ProdName": "Seagate Harddisk 500TB",
            "ManagersApproval": {
                "Status": "Approved",
                "ManagersDetails": [{
                        "Name": "Steve Rock",
                        "Email": "[email protected]"
                    }
                ],
                "Comments": ""
            },
            "AdminApproval": {
                "Status": "Approved",
                "AdminDetails": [{
                        "Name": "Hardy Lee",
                        "Email": "[email protected]"
                    },
                    {
                        "Name": "Moss Grant",
                        "Email": "[email protected]"
                    }
                ],
                "Comments": ""
            },
            "RequestStatus": "Approved"
        },
        {
            "ProdName": "Note Book - Large",
            "ManagerApproval": {
                "Status": "Approved",
                "Approver": [{
                    "Name": "Jet Lee",
                    "Email": "[email protected]"
                }],
                "Comments": "Approved by Jet Lee"
            },

            "AdminApproval": {
                "Status": "Approved",
                "AdminDetails": [{
                        "Name": "Hardy Lee",
                        "Email": "[email protected]"
                    },
                    {
                        "Name": "Moss Grant",
                        "Email": "[email protected]"
                    }
                ],
                "Comments": ""
            },
            "RequestStatus": "Completed"
        }
    ]
}

]

Upvotes: 1

Views: 649

Answers (1)

Elmer Dantas
Elmer Dantas

Reputation: 4859

First: you have a typo on the object properties. You have ManagerApproval on filter but has ManagersApproval (with S) properties among your data.

Second: the filter should be ng-repeat="a in data.ProdRequest | filter:{ProdName: prodName, ManagerApproval: { Status: managerApproval }}"

here's the working fiddle: https://jsfiddle.net/pnypxhj8/3/

Upvotes: 2

Related Questions