From 6fcee40f209ddac3c5e584f7bf4e9604aa517feb Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Fri, 18 Mar 2016 17:15:07 +0100 Subject: [PATCH] implemented search --- css/custom.css | 5 ++++ js/modules/pages/controllers/resultCtrl.js | 34 +++++++++++++++++++++- js/modules/pages/html/result.tmpl.html | 2 ++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/css/custom.css b/css/custom.css index 2aec337e..5c6347f8 100644 --- a/css/custom.css +++ b/css/custom.css @@ -694,4 +694,9 @@ svg.nvd3-svg { .msg-error { color:#F00; font-size:14px; +} + +.searchform { + color:#F00; + } \ No newline at end of file diff --git a/js/modules/pages/controllers/resultCtrl.js b/js/modules/pages/controllers/resultCtrl.js index 64c97194..4a08527a 100644 --- a/js/modules/pages/controllers/resultCtrl.js +++ b/js/modules/pages/controllers/resultCtrl.js @@ -152,6 +152,7 @@ $scope.restoreState(); $scope.count = sdata.length; $scope.gridOpts.data = sdata; + $scope.Data = sdata; $timeout(function () { angular.element($window).resize(); }, 0) @@ -468,6 +469,10 @@ //set gridApi on scope $scope.gridApi = gridApi; }; + + $scope.searchData = function() { + $scope.gridOpts.data = $filter('messageSearch')($scope.Data, $scope.gridOpts, $scope.searchText); + }; } ]) .filter('unixts', function() { @@ -479,5 +484,32 @@ return input; } }; - }); + }) + .filter('messageSearch', function() { + return function(data, grid, query) { + var matches = []; + + //no filter defined so bail + if (query === undefined|| query==='') { + return data; + } + + for (var i = 0; i < data.length; i++) { + for (var j = 0; j < grid.columnDefs.length; j++) { + + var dataItem = data[i]; + var fieldName = grid.columnDefs[j]['field']; + + if(dataItem[fieldName] === undefined) continue; + + if (dataItem[fieldName].toString().search(query)>-1) { + var n = dataItem[fieldName].toString().search(query); + matches.push(dataItem); + break; + } + } + } + return matches; + } + }); }(angular, homer)); diff --git a/js/modules/pages/html/result.tmpl.html b/js/modules/pages/html/result.tmpl.html index f174a368..bb2dccd0 100644 --- a/js/modules/pages/html/result.tmpl.html +++ b/js/modules/pages/html/result.tmpl.html @@ -7,6 +7,8 @@

+   +