[tableview] support for json-paginated table if paginable stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 01 Jun 2010 12:21:03 +0200
branchstable
changeset 5617 f0bc8f5ddee2
parent 5616 859225caf375
child 5618 24cc5d495fdf
[tableview] support for json-paginated table if paginable
web/views/tableview.py
--- a/web/views/tableview.py	Tue Jun 01 12:20:16 2010 +0200
+++ b/web/views/tableview.py	Tue Jun 01 12:21:03 2010 +0200
@@ -118,7 +118,8 @@
 
     def call(self, title=None, subvid=None, displayfilter=None, headers=None,
              displaycols=None, displayactions=None, actions=(), divid=None,
-             cellvids=None, cellattrs=None, mainindex=None):
+             cellvids=None, cellattrs=None, mainindex=None,
+             paginate=False, page_size=None):
         """Produces a table displaying a composite query
 
         :param title: title added before table
@@ -178,6 +179,9 @@
         if actions:
             self.render_actions(divid, actions)
         # render table
+        if paginate:
+            self.divid = divid # XXX iirk (see usage in page_navigation_url)
+            self.paginate(page_size=page_size, show_all_option=False)
         table = TableWidget(self)
         for column in self.get_columns(computed_labels, displaycols, headers,
                                        subvid, cellvids, cellattrs, mainindex):
@@ -187,6 +191,13 @@
         if not fromformfilter:
             self.w(u'</div>\n')
 
+    def page_navigation_url(self, navcomp, path, params):
+        rql = params.pop('rql', self.cw_rset.printable_rql())
+        # latest 'true' used for 'swap' mode
+        return 'javascript: replacePageChunk(%s, %s, %s, %s, true)' % (
+            dumps(self.divid), dumps(rql),
+            dumps(self.__regid__), dumps(params))
+
     def show_hide_actions(self, divid, currentlydisplayed=False):
         showhide = u';'.join(toggle_action('%s%s' % (divid, what))[11:]
                              for what in ('Form', 'Show', 'Hide', 'Actions'))