1 ng.module('smart-table')
2 .directive('stSearch', ['stConfig', '$timeout','$parse', function (stConfig, $timeout, $parse) {
5 link: function (scope, element, attr, ctrl) {
8 var throttle = attr.stDelay || stConfig.search.delay;
9 var event = attr.stInputEvent || stConfig.search.inputEvent;
11 attr.$observe('stSearch', function (newValue, oldValue) {
12 var input = element[0].value;
13 if (newValue !== oldValue && input) {
14 ctrl.tableState().search = {};
15 tableCtrl.search(input, newValue);
20 scope.$watch(function () {
21 return ctrl.tableState().search;
22 }, function (newValue, oldValue) {
23 var predicateExpression = attr.stSearch || '$';
24 if (newValue.predicateObject && $parse(predicateExpression)(newValue.predicateObject) !== element[0].value) {
25 element[0].value = $parse(predicateExpression)(newValue.predicateObject) || '';
29 // view -> table state
30 element.bind(event, function (evt) {
31 evt = evt.originalEvent || evt;
32 if (promise !== null) {
33 $timeout.cancel(promise);
36 promise = $timeout(function () {
37 tableCtrl.search(evt.target.value, attr.stSearch || '');