Beispiel #1
0
 def filtering_table_row(self, col):
     extra = getattr(col.filter, 'html_extra', {})
     return _HTML.tr(
         _HTML.th(self.filtering_col_label(col), class_='filter-label')
         + _HTML.td(self.filtering_col_op_select(col), class_='operator')
         + _HTML.td(
             _HTML.div(self.filtering_col_inputs1(col), class_='inputs1')
             + _HTML.div(self.filtering_col_inputs2(col), class_='inputs2')
         ),
         # Added _filter to address CSS collision with Bootstrap
         # Ref: https://github.com/level12/webgrid/issues/28
         class_=col.key + '_filter',
         **extra
     )
Beispiel #2
0
def th_sortable(current_order, column_order, label, url,
    class_if_sort_column="sort", class_if_not_sort_column=None, 
    link_attrs=None, name="th", **attrs):
    """<th> for a "click-to-sort-by" column.

    Convenience function for a sortable column.  If this is the current sort
    column, just display the label and set the cell's class to
    ``class_if_sort_column``.
    
    ``current_order`` is the table's current sort order.  ``column_order`` is
    the value pertaining to this column.  In other words, if the two are equal,
    the table is currently sorted by this column.

    If this is the sort column, display the label and set the <th>'s class to
    ``class_if_sort_column``.

    If this is not the sort column, display an <a> hyperlink based on
    ``label``, ``url``, and ``link_attrs`` (a dict), and set the <th>'s class
    to ``class_if_not_sort_column``.  
    
    ``url`` is the literal href= value for the link.  Pylons users would
    typically pass something like ``url=h.url_for("mypage", sort="date")``.

    ``**attrs`` are additional attributes for the <th> tag.

    If you prefer a <td> tag instead of <th>, pass ``name="td"``.

    To change the sort order via client-side Javascript, pass ``url=None`` and
    the appropriate Javascript attributes in ``link_attrs``.

    Examples:

    >>> sort = "name"
    >>> th_sortable(sort, "name", "Name", "?sort=name")
    literal(u'<th class="sort">Name</th>')
    >>> th_sortable(sort, "date", "Date", "?sort=date")
    literal(u'<th><a href="?sort=date">Date</a></th>')
    >>> th_sortable(sort, "date", "Date", None, link_attrs={"onclick": "myfunc()"})
    literal(u'<th><a onclick="myfunc()">Date</a></th>')
    """
    from webhelpers2.html import HTML
    if current_order == column_order:
        content = label
        class_ = class_if_sort_column
    else:
        link_attrs = link_attrs or {}
        content = HTML.a(label, href=url, **link_attrs)
        class_ = class_if_not_sort_column
    return HTML.th(content, class_=class_, **attrs)
Beispiel #3
0
 def table_th(self, col):
     label = col.label
     if self.grid.sorter_on and col.can_sort:
         url_args = {}
         url_args['dgreset'] = None
         url_args['sort2'] = None
         url_args['sort3'] = None
         cls = None
         if self.grid.order_by and len(self.grid.order_by) == 1:
             current_sort, flag_desc = self.grid.order_by[0]
             if current_sort == col.key:
                 cls = 'sort-' + ('desc' if flag_desc else 'asc')
             if current_sort != col.key or flag_desc:
                 url_args['sort1'] = col.key
             else:
                 url_args['sort1'] = '-{0}'.format(col.key)
         else:
             url_args['sort1'] = col.key
         label = _HTML.a(
             label,
             href=self.current_url(**url_args),
             class_=cls
         )
     return _HTML.th(label, **col.head.hah)