How do i implement exact match search filter for only one column and rest should not be exact match.
Let say i have a employee table with employee name and other details. I would like to filter name when its matched exactly but i want to leave the rest.
How do i do it in simple way?
What I have tried:
HTML:
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
table {
border-style: solid;
border-collapse:collapse;
}
th {
border-style: solid;
}
td {
border-style: solid;
}
</style>
</head>
<body ng-app="mymodule">
<div ng-controller="myController">
<table>
<thead>
<tr>
<th>Name</th>
<th>Gender</th>
<th>Salary</th>
<th>City</th>
</tr>
<tr>
<th><input type="text" ng-model="searchText.name" /></th>
<th><input type="text" ng-model="searchText.gender" /></th>
<th><input type="text" ng-model="searchText.salary" /></th>
<th><input type="text" ng-model="searchText.city" /></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee in employees | filter:searchText">
<td> {{ employee.name }} </td>
<td> {{ employee.gender }} </td>
<td> {{ employee.salary }} </td>
<td> {{ employee.city }} </td>
</tr>
</tbody>
</table>
</div>
</body>
<script src="Scripts/angular.min.js"></script>
<script src="JavaScript.js"></script>
</html>
Angular:
var app = angular.module("mymodule", []);
app.controller("myController", function ($scope) {
var employees = [
{ name: "Ben", gender: "Male", salary: 55000, city: "London" },
{ name: "Sara", gender: "Female", salary: 68000, city: "Newyork" },
{ name: "Mark", gender: "Male", salary: 57000, city: "Ashland" },
{ name: "Pam", gender: "Female", salary: 53000, city: "Hongkong" },
{ name: "Todd", gender: "Male", salary: 60000, city: "London" },];
$scope.employees = employees;
$scope.flag = function () {
if ($searchText.name === employees.name) {
return true;
}
}
});