From 27256d41e35562a173bd6fcda53df130e1e8304c Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <renaud.legac@free.fr> Date: Thu, 25 Nov 2010 20:45:08 +0000 Subject: [PATCH] Introduce the grid plugin pGridPaging. --- models/db_widgets.py | 4 ++-- modules/plugin_dbui/dbsvc.py | 11 ++++++----- static/plugin_dbui/lib/appgrid.js | 4 +++- static/plugin_dbui/lib/appgridpaging.js | 23 +++++++++++++++++++++++ static/plugin_dbui/lib/appjsonstore.js | 1 + 5 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 static/plugin_dbui/lib/appgridpaging.js diff --git a/models/db_widgets.py b/models/db_widgets.py index 595fdc0a..aa6ba2bd 100644 --- a/models/db_widgets.py +++ b/models/db_widgets.py @@ -77,8 +77,8 @@ pgm.customize_form('publications', ) -pgm.customize_grid(plugins=['pGridRowEditorToolbar', - 'pGridRowEditorContextMenu']) +pgm.customize_grid(plugins=['pGridRowEditorContextMenu', + 'pGridPagingBar',]) # add template column to grid diff --git a/modules/plugin_dbui/dbsvc.py b/modules/plugin_dbui/dbsvc.py index c7233585..aa683f06 100644 --- a/modules/plugin_dbui/dbsvc.py +++ b/modules/plugin_dbui/dbsvc.py @@ -380,17 +380,18 @@ class DbSvc(BaseSvc): query = '' if "where" in self._vars: query = self._encode_query(self._list(self._vars["where"])) - + # handle paging options (see Ext.PagingToolbar) - kwargs = {} + # Count the number of record in the table --require for the paging + kwargs, results = {}, None if 'start' in self._vars and 'limit' in self._vars: kwargs['limitby'] = (int(self._vars.start), int(self._vars.limit)) - - # proceed the select + results = self._db(self._db[table].id).count() + rows = self._db(query).select(*fields, **kwargs) self._debug("End DbSvc.read") - return {"success": True, "data": rows_serializer(rows)} + return {"success": True, "results": results, "data": rows_serializer(rows)} def select(self): diff --git a/static/plugin_dbui/lib/appgrid.js b/static/plugin_dbui/lib/appgrid.js index 98f0e37d..548efda1 100644 --- a/static/plugin_dbui/lib/appgrid.js +++ b/static/plugin_dbui/lib/appgrid.js @@ -70,8 +70,10 @@ App.grid.Grid = Ext.extend(Ext.grid.GridPanel, { // the columns model this.columns = this.model.colModel; - // empty top toolbar -- require by the toolbar plugin + // empty top toolbar/bottomnar -- required by the plugins this.tbar = []; + this.bbar = new Ext.PagingToolbar(); + this.bbar.hide(); // initialize the underlying class. DON'T MOVE App.grid.Grid.superclass.initComponent.call(this); diff --git a/static/plugin_dbui/lib/appgridpaging.js b/static/plugin_dbui/lib/appgridpaging.js new file mode 100644 index 00000000..350143c3 --- /dev/null +++ b/static/plugin_dbui/lib/appgridpaging.js @@ -0,0 +1,23 @@ +/** + * The paging bottom bar plugin + * + * The ptype of this component is pGridPagingBar. + * + * @version $Id$ + * + */ +Ext.namespace('App.grid'); + +App.grid.PagingBar = Ext.extend(Object, { + + init: function(grid){ + + var bbar = grid.getBottomToolbar(); + bbar.bindStore(grid.store); + bbar.pageSize = 2; + bbar.doRefresh(); + bbar.show(); + }, +}); + +Ext.preg('pGridPagingBar', App.grid.PagingBar); diff --git a/static/plugin_dbui/lib/appjsonstore.js b/static/plugin_dbui/lib/appjsonstore.js index 95e7dde1..adc05259 100644 --- a/static/plugin_dbui/lib/appjsonstore.js +++ b/static/plugin_dbui/lib/appjsonstore.js @@ -152,6 +152,7 @@ App.data.JsonStore = Ext.extend(Ext.data.Store, { this.reader = new Ext.data.JsonReader({ root: 'data', fields: this.model.fields, + totalProperty: 'results', idProperty: this.model.idProperty, }); } -- GitLab