Monday, 24 April 2017

AngularJS-16 : filter on multiple columns (Hardcoded and customized method)

AngularJS-16 : filter on multiple columns (Hardcoded and customized method)











angular.min.js
-------------------------------------


Script.js
------------------------------------

/// <reference path="angular.min.js" />

var myAppModule = angular.module("myAppModule",[]).controller("myDataController",function ($scope) {
        var employees =
            [
                {
                    firstName : "pavan",
                    lastName : "kumar",
                    gender : "Male",
                    city : "Bangalore"
                },
                {
                    firstName : "ram",
                    lastName : "kumar",
                    gender : "Male",
                    city : "Mysore"
                },
                {
                    firstName : "madhu",
                    lastName : "soodhan",
                    gender : "Male",
                    city : "Tumkur"
                },
                {
                    firstName : "Parva",
                    lastName : "Bhadragiri",
                    gender : "Male",
                    city : "Vijayvada"
                }
            ]
    $scope.employees = employees;
    $scope.search = function(item){
        if($scope.searchEmp == undefined){
            return true;
        }
        else {
                if(item.firstName.toLowerCase().indexOf($scope.searchEmp.toLowerCase()) != -1 ||
                item.city.toLowerCase().indexOf($scope.searchEmp.toLowerCase()) != -1){
                    return true;
                }
        }
        return false;
       
    }

});




myHTML.html
---------------------------------------


<!DOCTYPE html>
<html ng-app="myAppModule">
    <head>
        <script type="text/javascript" src="resources/js/angular.min.js"></script>
        <script type="text/javascript" src="resources/js/Script.js"></script>
        <link type="text/css" rel="stylesheet" href="resources/myCSS.css"/>
    </head>
    <body ng-controller="myDataController">
    <input type="text" placeholder="Search name and city" ng-model="searchEmp"/>
        <br/><br/>
        <table>
            <thead>
                <tr>
                    <th>First Name </th>
                    <th>Last Name</th>
                     <th>Gender</th>
                     <th>City</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="emp in employees | filter:search">
                    <td>{{emp.firstName}}</td>
                    <td>{{emp.lastName}}</td>
                    <td>{{emp.gender}}</td>
                    <td>{{emp.city}}</td>
                </tr>
            </tbody>
        </table>
       
   
    </body>
</html>
















No comments:

Post a Comment

AngularJS-24 : Router

AngularJS-24 : Router https://www.youtube.com/watch?v=hThmoKA9aeU#t=427.383649 Download "angular-route.min.js"and add to p...