Feature: Debounced the filtering of employees to 350ms to make it smoother.
This commit is contained in:
parent
ff3c375295
commit
88b641b4f2
@ -23,7 +23,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="tbodyMain">
|
<tbody id="tbodyMain">
|
||||||
<tr ng-repeat="item in getEmployees(search)">
|
<tr ng-repeat="item in employees">
|
||||||
<td>{{item.Code}}</td>
|
<td>{{item.Code}}</td>
|
||||||
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
|
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
|
||||||
<td>{{item.Designation}}</td>
|
<td>{{item.Designation}}</td>
|
||||||
|
@ -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) {
|
if (q !== $scope._search) {
|
||||||
$scope._search = q;
|
$scope._search = q;
|
||||||
if (angular.isUndefined(q) || q === '') {
|
if (angular.isUndefined(q) || q === '') {
|
||||||
@ -20,9 +24,11 @@ var EmployeeListCtrl = ['$scope', '$location', '$routeParams', 'employees', func
|
|||||||
} else {
|
} else {
|
||||||
$location.path('/Employees').search({'q': q}).replace();
|
$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) {
|
$scope.doFilter = _.memoize(function (q) {
|
||||||
var matches = [], i, len;
|
var matches = [], i, len;
|
||||||
if (angular.isUndefined(q) || q === '') {
|
if (angular.isUndefined(q) || q === '') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user