Pinned Rows — Django-tables2 2.3.1 Documentation

django-tables2 latest

Getting started

  • Installation
  • Tutorial
  • Populating a table with data

Customization

  • Alternative column data
  • Alternative column ordering
  • Column and row attributes
  • Customizing headers and footers
  • Swapping the position of columns
  • Pagination
  • Table Mixins
  • Customizing table style
  • Query string fields
  • Controlling localization
  • Class Based Generic Mixins
  • Pinned rows
    • Attributes for pinned rows
  • Filtering data in your table
  • Exporting table data

Reference

  • API
  • FAQ
  • Upgrading and change log
  • Glossary
django-tables2
  • Pinned rows
  • Edit on GitHub
Pinned rows¶

This feature allows one to pin certain rows to the top or bottom of your table. Provide an implementation for one or two of these methods, returning an iterable (QuerySet, list of dicts, list objects) representing the pinned data:

  • get_top_pinned_data(self) - Displays the returned rows on top.

  • get_bottom_pinned_data(self) - Displays the returned rows at the bottom.

Pinned rows are not affected by sorting and pagination, they will be present on every page of the table, regardless of ordering. Values will be rendered just like you are used to for normal rows.

Example:

class Table(tables.Table): first_name = tables.Column() last_name = tables.Column() def get_top_pinned_data(self): return [ {"first_name": "Janet", "last_name": "Crossen"}, # key "last_name" is None here, so the default value will be rendered. {"first_name": "Trine", "last_name": None} ]

Note

If you need very different rendering for the bottom pinned rows, chances are you actually want to use column footers: Adding column footers

Attributes for pinned rows¶

You can override the attributes used to render the <tr> tag of the pinned rows using: pinned_row_attrs. This works exactly like Row attributes.

Note

By default the <tr> tags for pinned rows will get the attribute class="pinned-row".

<tr class="odd pinned-row" ...> [...] </tr> <tr class="even pinned-row" ...> [...] </tr>

Từ khóa » đan Row