Angular Filter Nested JSON Hierarchical Treeview in Controller

Angular Filter Nested JSON Hierarchical Treeview in Controller

Angular Filter Nested JSON Hierarchical Treeview in Controller

In this Post We Will Explain About is Angular Filter Nested JSON Hierarchical Treeview in Controller With Example and Demo.Welcome on infinityknow.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Angularjs Filter JSON hierarchy tree in controllerExample

In this post we will show you Best way to implement Filter JSON In Hierarchical Way Using AngularJS, hear for filtering – AngularJS displaying hierarchical datawith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Make a HTML file and define markup



<title>Filter JSON In Nested Using AngularJS Example</title>


.live_panel {
 margin:auto;
 width:800px;
}



//some code.........

</html

Make a Body Part define markup

	<div class="live_panel">
		
            <li>{{data.name}}</li>
            <li> 0">
               <ul></ul>
            </li>
        
		<div>Enter Programing text to filter data</div>
		<div>
			
		</div>
		<div>
			<ul>
				<li>{{data.name}}
					<div> 0">
						<ul></ul>
					</div>
				</li>
			</ul>
			<ul>
				<li>{{data.name}}
					<div> 0">
						<ul></ul>
					</div>
				</li>
			</ul>
		</div>
	</div>

Make a js file and define scripting

E-junkie: Sell digital downloads online

E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!

Also see:

  1. The Top 10+ Best Webinar Software Platforms For 2020-2021
  2. Build Your Future Godaddy Careers And Jobs
  3. Introduction To Web Hosting Services

Create a Module

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

Create a Simple Controller using AngularJS

function liveCtrl($scope) {
	$scope.postData = [ {
		"name" : "Java Script",
		"second_chield" : [ {
			"name" : "Angularjs",
			"second_chield" : []
		}, {
			"name" : "Vue js",
			"second_chield" : []
		} ]
	}, {
		"name" : "Server Side",
		"second_chield" : [ {
			"name" : "PHP",
			"second_chield" : []
		}, {
			"name" : "Laravel",
			"second_chield" : []
		} ]
	}, {
		"name" : "Google",
		"second_chield" : [ {
			"name" : "Youtube",
			"second_chield" : []
		}, {
			"name" : "Analytics",
			"second_chield" : []
		} ]
	} ];
	$scope.all_programdata = [];

	$scope.$watch('query_str', function() {
		if ($scope.query_str == null || $scope.query_str.length == 0) {
			$scope.display_filterdata = false;
		} else {
			$scope.all_programdata = [];
			var temp = angular.copy($scope.postData);
			$scope.convert_lower_str = $scope.query_str
					.toLowerCase();
			$scope.filterResources(temp);
			$scope.display_filterdata = true;
			$scope.all_programdata = temp;
		}
	});

	$scope.filterResources = function(program_list) {
		for (var i = 0; i  0) {
				$scope.filterResources(program_list[i].second_chield);
				if (program_list[i].second_chield.length == 0) {
					var name = program_list[i].name.toLowerCase();
					if (!(name.indexOf($scope.convert_lower_str) >= 0)) {
						program_list.splice(i, 1);
						i--;
					}
				}
			} else {
				var name = program_list[i].name.toLowerCase();
				if (!(name.indexOf($scope.convert_lower_str) >= 0)) {
					program_list.splice(i, 1);
					i--;
				}
			}
		}
	};

}

Full Code : Filter JSON In Nested Using AngularJS Example



<title>Filter JSON In Nested Using AngularJS Example</title>


.live_panel {
 margin:auto;
 width:800px;
}




	<div class="live_panel">
		
            <li>{{data.name}}</li>
            <li> 0">
               <ul></ul>
            </li>
        
		<div>Enter Programing text to filter data</div>
		<div>
			
		</div>
		<div>
			<ul>
				<li>{{data.name}}
					<div> 0">
						<ul></ul>
					</div>
				</li>
			</ul>
			<ul>
				<li>{{data.name}}
					<div> 0">
						<ul></ul>
					</div>
				</li>
			</ul>
		</div>
	</div>
	
var liveApp = angular.module('liveApp', []);

function liveCtrl($scope) {
	$scope.postData = [ {
		"name" : "Java Script",
		"second_chield" : [ {
			"name" : "Angularjs",
			"second_chield" : []
		}, {
			"name" : "Vue js",
			"second_chield" : []
		} ]
	}, {
		"name" : "Server Side",
		"second_chield" : [ {
			"name" : "PHP",
			"second_chield" : []
		}, {
			"name" : "Laravel",
			"second_chield" : []
		} ]
	}, {
		"name" : "Google",
		"second_chield" : [ {
			"name" : "Youtube",
			"second_chield" : []
		}, {
			"name" : "Analytics",
			"second_chield" : []
		} ]
	} ];
	$scope.all_programdata = [];

	$scope.$watch('query_str', function() {
		if ($scope.query_str == null || $scope.query_str.length == 0) {
			$scope.display_filterdata = false;
		} else {
			$scope.all_programdata = [];
			var temp = angular.copy($scope.postData);
			$scope.convert_lower_str = $scope.query_str
					.toLowerCase();
			$scope.filterResources(temp);
			$scope.display_filterdata = true;
			$scope.all_programdata = temp;
		}
	});

	$scope.filterResources = function(program_list) {
		for (var i = 0; i  0) {
				$scope.filterResources(program_list[i].second_chield);
				if (program_list[i].second_chield.length == 0) {
					var name = program_list[i].name.toLowerCase();
					if (!(name.indexOf($scope.convert_lower_str) >= 0)) {
						program_list.splice(i, 1);
						i--;
					}
				}
			} else {
				var name = program_list[i].name.toLowerCase();
				if (!(name.indexOf($scope.convert_lower_str) >= 0)) {
					program_list.splice(i, 1);
					i--;
				}
			}
		}
	};

}
	



Example

READ :  Apache Exclude Directory Limit Directive using htaccess

I hope you have Got What is Angularjs Filter Nested JSON Hierarchical Treeview in Controller And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.