Commit d2b3c22d authored by Alain Leufroy's avatar Alain Leufroy
Browse files

[views] use class attributes for options instead of kwargs

We stick to the "new-table" way of specifying options.
parent e9ca9c8f6ed3
......@@ -35,8 +35,7 @@ The simplest way is to call:
self._cw.wview('slickgrid', rset, 'null')
Although, because it inherites from cubicweb `table` view, options can
be specified at selection time:
Options can be specified by class attributes:
* `displaycols`, if not `None`, should be a list of rset's columns to be
displayed.
......@@ -57,9 +56,12 @@ One can use:
.. sourcecode:: python
self._cw.wview('slickgrid', rset, 'null',
headers=(_('first'), _('second'), _('third')),
cellvids={0: 'text', 1: 'inline', 2:'outofcontext'},
columns_options={0: {'sortable': False}})
class MyRsetGridView(RsetGridView):
__regid__ = 'myslickgrid'
headers = (_('first'), _('second'), _('third'))
cellvids = {0: 'text', 1: 'inline', 2:'outofcontext'}
columns_options = {0: {'sortable': False}}
self._cw.wview('myslickgrid', rset, 'null')
Note that the pagination is not working yet.
\ No newline at end of file
......@@ -144,28 +144,22 @@ class RsetGridView(tableview.RsetTableView):
result set to compute column names and the proper way to display
the cells.
It is highly configuration and accepts the same wealth of option than
:class:`cubicweb.web.view.tableview.RsetTableView` plus the followings:
It is highly configurable and accepts the same wealth of option than
:class:`cubicweb.web.view.tableview.RsetTableView` plus the following:
* `default_grid_options`: a dictionary containing slickgrid grid
options, see https://github.com/mleibman/SlickGrid/wiki/Grid-Options
* `default_column_options`: slickgrid option applied to every
columns, see
* `default_column_options`: slickgrid options applied to every
column by default, see
https://github.com/mleibman/SlickGrid/wiki/Column-Options
* `columns_options`: a dictionary referencing a column index to a
dict of slickgrid # column options. This completly overright the
dict of slickgrid # column options. This completely overrides the
default column options set in `default_column_options`.
`columns_options` can be set at selection time.
"""
__regid__ = 'slickgrid'
# The default selector of RsetTableView try to deal with TableView
# backward compat by selecting RsetTableView with exact matching kwargs
# but we want to accept additional kwargs.
__select__ = tableview.AnyRsetView.__select__
layout_id = 'slickgrid_layout'
default_column_renderer_class = RsetGridColRenderer
handle_pagination = False # pagination does not works well for now
......@@ -180,13 +174,11 @@ class RsetGridView(tableview.RsetTableView):
default_column_options = {'focusable': False}
columns_options = None
def call(self, columns_options=None, **kwargs):
self.columns_options = columns_options or self.columns_options or {}
super(RsetGridView, self).call(**kwargs)
def get_column_options(self, colid):
'''Return a dictionary containing'''
column_options = self.columns_options.get(colid, {})
if not column_options:
column_options = self.default_column_options
if self.columns_options is None:
return self.default_column_options
column_options = self.columns_options.get(colid, None)
if column_options is None:
return self.default_column_options
return column_options
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment