From 6eb57275024dbdc0eb5a758c46a7895c9abef5cc Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <legac@cppm.in2p3.fr> Date: Mon, 25 Nov 2013 18:24:23 +0100 Subject: [PATCH] ExtJS 4.2: Draft version of the "buffered grid" using buffered store. --- controllers/toolbox.py | 17 ++++++++++++++ models/widgets_grids.py | 2 +- models/widgets_stores.py | 9 +++++++- models/widgets_viewport.py | 3 ++- modules/plugin_dbui/gridmodifier.py | 4 +++- modules/plugin_dbui/storemodifier.py | 34 ++++++++++++++++++++++++++++ static/plugin_dbui/src/grid.js | 20 +++++++++------- 7 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 controllers/toolbox.py diff --git a/controllers/toolbox.py b/controllers/toolbox.py new file mode 100644 index 00000000..90d6d410 --- /dev/null +++ b/controllers/toolbox.py @@ -0,0 +1,17 @@ +""" Collection of tools to help debugging, .... + +""" + +def fill_categories(): + """Fill the categories table with a large number of data. + Usefull to test the buffered render. + + """ + data = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', \ + 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'] + + for i in range(1, (1000/len(data))+1): + for el in data: + s = el*i + print s + db.categories[0] = dict(code=s, definition=s.lower()) diff --git a/models/widgets_grids.py b/models/widgets_grids.py index 9f65e4bb..048c63ed 100644 --- a/models/widgets_grids.py +++ b/models/widgets_grids.py @@ -17,7 +17,7 @@ dbui.configure_grids(db, plugins=['pGridRowEditorConfirmDelete', # gridModifier = dbui.GridModifier('categories') gridModifier.configure_column('code', width=10) -gridModifier.set_rownumbering(False) +gridModifier.set_rownumbering(True) gridModifier.append_filter(('code', 'contains', T('bla bla...'))) gridModifier.set_filters(plugins=['pFormToolTip'], diff --git a/models/widgets_stores.py b/models/widgets_stores.py index 45b9989a..65e22065 100644 --- a/models/widgets_stores.py +++ b/models/widgets_stores.py @@ -5,7 +5,14 @@ #------------------------------------------------------------------------------- # -# teams +# categories (buffered) +# +storeModifier = dbui.StoreModifier('categories') +storeModifier.set_buffered() + +#------------------------------------------------------------------------------- +# +# teams (order by) # storeModifier = dbui.StoreModifier('teams') storeModifier.orderby(~db.teams.team) diff --git a/models/widgets_viewport.py b/models/widgets_viewport.py index 4fbcdd49..29524f81 100644 --- a/models/widgets_viewport.py +++ b/models/widgets_viewport.py @@ -62,5 +62,6 @@ viewportModifier.append_plugins('pViewportLogin') viewportModifier.configure(logged=True); viewportModifier.add_node(helpNode, casNode, formNode, gridNode, reportNode) +viewportModifier.default_node(T('Tables'), T('categories')) +# viewportModifier.default_node(T('Tables'), T('new_fields')) # viewportModifier.default_node(T('Tables'), T('publications')) -viewportModifier.default_node(T('Tables'), 'new_fields') diff --git a/modules/plugin_dbui/gridmodifier.py b/modules/plugin_dbui/gridmodifier.py index cf8839b3..560f69b2 100644 --- a/modules/plugin_dbui/gridmodifier.py +++ b/modules/plugin_dbui/gridmodifier.py @@ -80,7 +80,9 @@ class GridModifier(Modifier): """ Modifier.__init__(self, MODIFIER_GRIDS, tablename) - + + self._tablename = tablename + if 'configure_columns' not in self.data: self.data.configure_columns = {} self.data.delete_columns = [] diff --git a/modules/plugin_dbui/storemodifier.py b/modules/plugin_dbui/storemodifier.py index 3dca49f6..b3d897ec 100644 --- a/modules/plugin_dbui/storemodifier.py +++ b/modules/plugin_dbui/storemodifier.py @@ -95,3 +95,37 @@ class StoreModifier(Modifier): """ self.data.orderby.extend(fields) + + + def set_buffered(self, **kwargs): + """ The store is buffered. + The method set the following configuration options: + + - autoLoad = False + - buffered = True + - pageSize = 25 + - leadingBufferZone = 0 + - trailingBufferZone = 0 + + They can be overwritten using the keyword arguments. + + The grid buffering is activate when the store is buffered. + That means that only 5 pages are kept in the cache. Therefore + this is a good option to manipulate almost infinite set of data. + + @param kwargs: Any configuration parameter of the C{Ext.data.Store}. + Those related to the buffering are C{buffered}, C{clearOnPaqgeLoad}, + C{leadingBufferZone}, C{pageSize}, C{purgePageCount} + and C{trailingBufferZone}. + + """ + di = dict(autoLoad=False, + buffered=True, + pageSize=25, + leadingBufferZone=0, + trailingBufferZone=0) + + di.update(kwargs) + + self.configure(**di) + \ No newline at end of file diff --git a/static/plugin_dbui/src/grid.js b/static/plugin_dbui/src/grid.js index 7d87f941..5c009505 100644 --- a/static/plugin_dbui/src/grid.js +++ b/static/plugin_dbui/src/grid.js @@ -44,14 +44,18 @@ Ext.define('App.grid.Grid', { // initialise the base class this.callParent(arguments); - // load the store if not yet done - // if the grid paging is used load only the first 10 rows - if (!this.store.getTotalCount()) { - if (App.isPlugin(this, 'pGridPaging')) { - this.store.load({params: {start: 0, limit: this.nRows}}); - } else { - this.store.load(); - } + // consistency check + if (this.store.buffered) { + this.store.getProxy().pageParam = 'page'; + } + + // load the first page when the buffering is on + if (this.findPlugin('bufferedrenderer')) { + this.store.loadPage(1); + + // load the full data set + } else if (!this.store.getTotalCount()) { + this.store.load(); } }, -- GitLab