Feature: Debounced the filtering of employees to 350ms to make it smoother.

This commit is contained in:
Tanshu 2013-10-07 13:21:59 +05:30
parent ff3c375295
commit 88b641b4f2
2 changed files with 10 additions and 4 deletions

View File

@ -23,7 +23,7 @@
</tr>
</thead>
<tbody id="tbodyMain">
<tr ng-repeat="item in getEmployees(search)">
<tr ng-repeat="item in employees">
<td>{{item.Code}}</td>
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td>{{item.Designation}}</td>

View File

@ -12,7 +12,11 @@ var EmployeeListCtrl = ['$scope', '$location', '$routeParams', 'employees', func
});
};
$scope.getEmployees = function (q) {
$scope.$watch('search', function (newValue, oldValue) {
$scope.filterEmployees(newValue);
}, true);
$scope.filterEmployees = _.debounce(function (q) {
if (q !== $scope._search) {
$scope._search = q;
if (angular.isUndefined(q) || q === '') {
@ -20,9 +24,11 @@ var EmployeeListCtrl = ['$scope', '$location', '$routeParams', 'employees', func
} else {
$location.path('/Employees').search({'q': q}).replace();
}
$scope.$apply(function () {
$scope.employees = $scope.doFilter(q);
});
}
return $scope.doFilter(q);
};
}, 350);
$scope.doFilter = _.memoize(function (q) {
var matches = [], i, len;
if (angular.isUndefined(q) || q === '') {