doc/book/en/devweb/views/table.rst
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 22 Sep 2011 19:02:36 +0200
branchstable
changeset 7836 0ada13ce2e16
parent 6343 4814d44405fc
child 7992 4ff9f25cb06e
permissions -rw-r--r--
[doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly also properly deprecates SecondaryView as it should have been done a while ago.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5312
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
     1
Table view
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
     2
----------
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
     3
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
     4
(:mod:`cubicweb.web.views.tableview`)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
*table*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
    Creates a HTML table (`<table>`) and call the view `cell` for each cell of
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
    the result set. Applicable on any result set.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
6343
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    10
*editable-table*
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    11
    Creates an **editable** HTML table (`<table>`) and call the view `cell` for each cell of
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    12
    the result set. Applicable on any result set.
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    13
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
*cell*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    15
    By default redirects to the `final` view if this is a final entity or
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
    `outofcontext` view otherwise
5312
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
    17
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
    18
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
    19
API
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
    20
```
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
    21
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
    22
.. autoclass:: cubicweb.web.views.tableview.TableView
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5266
diff changeset
    23
   :members:
6343
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    24
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    25
Example
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    26
```````
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    27
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    28
Let us take an example from the timesheet cube:
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    29
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    30
.. sourcecode:: python
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    31
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    32
    class ActivityTable(EntityView):
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    33
        __regid__ = 'activitytable'
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    34
        __select__ = is_instance('Activity')
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    35
        title = _('activitytable')
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    36
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    37
        def call(self, showresource=True):
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    38
            _ = self._cw._
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    39
            headers  = [_("diem"), _("duration"), _("workpackage"), _("description"), _("state"), u""]
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    40
            eids = ','.join(str(row[0]) for row in self.cw_rset)
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    41
            rql = ('Any R, D, DUR, WO, DESCR, S, A, SN, RT, WT ORDERBY D DESC '
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    42
                   'WHERE '
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    43
                   '   A is Activity, A done_by R, R title RT, '
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    44
                   '   A diem D, A duration DUR, '
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    45
                   '   A done_for WO, WO title WT, '
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    46
                   '   A description DESCR, A in_state S, S name SN, A eid IN (%s)' % eids)
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    47
            if showresource:
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    48
                displaycols = range(7)
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    49
                headers.insert(0, display_name(self._cw, 'Resource'))
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    50
            else: # skip resource column if asked to
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    51
                displaycols = range(1, 7)
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    52
            rset = self._cw.execute(rql)
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    53
            self.wview('editable-table', rset, 'null',
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    54
                       displayfilter=True, displayactions=False,
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    55
                       headers=headers, displaycols=displaycols,
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    56
                       cellvids={3: 'editable-final'})
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    57
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    58
To obtain an editable table, specify 'edtitable-table' as vid. You
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    59
have to select the entity in the rql request too (in order to kwnow
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    60
which entity must be edited). You can specify an optional
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    61
`displaycols` argument which defines column's indexes that will be
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    62
displayed. In the above example, setting `showresource` to `False`
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    63
will only render columns from index 1 to 7.
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    64
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    65
The previous example results in:
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    66
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    67
.. image:: ../../images/views-table-shadow.png
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    68
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    69
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    70
In order to activate table filter mechanism, set the `displayfilter`
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    71
argument to True. A small arrow will be displayed at the table's top
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    72
right corner. Clicking on `show filter form` action, will display the
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    73
filter form as below:
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    74
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    75
.. image:: ../../images/views-table-filter-shadow.png
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    76
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    77
By the same way, you can display all registered actions for the
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    78
selected entity, setting `displayactions` argument to True.