From 3f00d133f769dd77eb1fb29c0abe151375e28183 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 11 Feb 2015 10:43:43 -0500 Subject: [PATCH] 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 --- Open-ILS/web/js/ui/default/staff/services/grid.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 = -- 2.11.0