To apply multiple deep property filtering, a custom filter needs to be created.
In other words, we must develop our own function to filter the data within an object and return the desired object (the filtered object).
For instance, let's say we want to filter data from the following object -
[
{
"document":{
"documentid":"1",
"documenttitle":"test 1",
"documentdescription":"abcdef"
}
},
{
"document":{
"documentid":"2",
"documenttitle":"dfjhkjhf",
"documentdescription":"dfhjshfjdhsj"
}
}
]
In HTML, the ng-repeat directive is used to display the document list -
<div>
//search input textbox
<input ng-model="searchDocument" placeholder="Search">
</div>
<div ng-repeat="document in documentList | filter: filteredDocument">
//our html code
</div>
In the Controller, a filter function is written to retrieve the filtered object based on two properties of the object, which are "document title" and "document description". An example of the code is shown below -
function filterDocuments(document)
{
if($scope.searchDocument)
{
if(document.documentTitle.toLowerCase().indexOf($scope.searchDocument.toLowerCase()) !== -1 || document.document.shortDescription.toLowerCase().indexOf($scope.searchDocument.toLowerCase()) !== -1)
{
//returns filtered object
return document
}
}else {
return document;
}
}
Here, $scope.searchDocument represents the scope variable connected to the search textbox in the HTML input tag, allowing users to enter text for searching.