Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I had a Json data I need to create a nested filter search in angular. If you guys can help me since I am new to this I tried but I find difficulty.

share|improve this question
    
you should make a fiddle – Ronnie Dec 6 at 18:44
up vote 0 down vote accepted

I dont have your css but at high level it should be like THIS and for multilevel filter refer THIS

On click of checkbox i am adding filter category to one of my array using addToFilter function.

HTML

<input  type="checkbox" ng-checked="item.checked" ng-model="item.checked" ng-click="addToFilter(item.node.category)"/> {{ item.node.category }}

HTML

code filter:categoryFilter will filter records from array according to selected category.

<div ng-repeat="item in nodes | filter:categoryFilter | orderBy:'node.location' | groupBy:['node.location'] ">
    <h2 ng-show="item.group_by_CHANGED">{{item.node.location}}</h2>
        <ul>
            <li>{{item.node.title}}</li>
         </ul></div>

JS

This js code is to add selected category from array when checked and remove when unchecked.

$scope.filtersApplied =[];
$scope.addToFilter = function(category)
{
  var i = $.inArray(category.trim(), $scope.filtersApplied);
  console.log(category);
  if (i > -1) {
     $scope.filtersApplied.splice(i, 1);
   } else {
     $scope.filtersApplied.push(category.trim());
   }
}
$scope.categoryFilter = function(node) {
   if ($scope.filtersApplied.length > 0) {
     if ($.inArray(node.node.category.trim(), $scope.filtersApplied) < 0)
     return;
   }
 return node;
}

** Please ignore my grouping code. I just want to simulate what you shown in image.

Updated SAMPLE with CSS

share|improve this answer
    
Hello, you gave exact way what I need but you just copying the Json data but I need to call it every time since it is dynamic data and it will be change every tim. Coming to the color part is there any way I can generate random classes to the locations names since I need to assign different colors to the different location. Please let me know. Thanks a ton for your help. – ravi yarlagadda 2 days ago
    
Angular supports two way binding so when you change your variable with new data all filter and grouping will get updated automatically for you. For COLOR CSS you can create your custom class and apply based on index. To achieve that, you need to group first and identify headers and keep track of indexes. Based on index you can apply CSS and it will remain fix at the time of filtering. I have updated sample for you. There are many ways you can achieve it. – user3249448 yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.