From: Bill Erickson Date: Wed, 11 Feb 2015 15:43:43 +0000 (-0500) Subject: webstaff: Grid supports automatic refresh with query change X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=370a7d12a366ff26c4f354f6da96a86ace6e7252;p=Evergreen.git webstaff: Grid supports automatic refresh with query change Adds a new gridControls function watchQuery(), which returns the contents of the grid query. When the contents change, the grid automatically redraws. Signed-off-by: Bill Erickson Signed-off-by: Jason Etheridge Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- diff --git a/Open-ILS/web/js/ui/default/staff/services/grid.js b/Open-ILS/web/js/ui/default/staff/services/grid.js index ccb9b40a2f..2c1a482e69 100644 --- a/Open-ILS/web/js/ui/default/staff/services/grid.js +++ b/Open-ILS/web/js/ui/default/staff/services/grid.js @@ -53,6 +53,13 @@ angular.module('egGridMod', // itemRetrieved : function(item) {} // allItemsRetrieved : function() {} // + // --- + // If defined, the grid will watch the return value from + // the function defined at watchQuery on each digest and + // re-draw the grid when query changes occur. + // + // watchQuery : function() { /* return grid query */ } + // // --------------- // These functions are defined by the grid and thus // replace any values defined for these attributes from the @@ -214,6 +221,17 @@ angular.module('egGridMod', controls.refresh(); } + if (controls.watchQuery) { + // capture the initial query value + grid.dataProvider.query = controls.watchQuery(); + + // watch for changes + $scope.gridWatchQuery = controls.watchQuery; + $scope.$watch('gridWatchQuery()', function(newv) { + controls.setQuery(newv); + }, true); + } + // if the caller provided a functional setSort // extract the value before replacing it grid.dataProvider.sort =