-
Notifications
You must be signed in to change notification settings - Fork 55
API Reference
In order to define the model data source and customize attributes of the table, table options provide a way to define global settings for table.
-
The model class that binded to the table, the queryset contains all objects for this model will be used to render table by default. It is the basic form to offer the data source.
type: classobj
default: None
# models.py class Person(models.Model): name = models.CharField(max_length=40) # tables.py from table import Table from table.columns import Column class PersonTable(Table): id = Column(field='id') name = Column(field='name') class Meta: model = Person
-
The id attribute for
<table>
tag, it will rendered as<table id="id">
. If not present, it will use your table class name inherit fromtable.Table
in lowcase form.type: string
default: None
-
Allows custom HTML attributes to be specified which will be added to the
<table>
tag. Note: attrs should not contains id key.type: dict
default: {}
# tables.py from table import Table from table.columns import Column class PersonTable(Table): id = Column(field='id') name = Column(field='name') class Meta: attrs = {'class': 'custom_class'}
-
Allows changing default behavior about sorting. By this varible, you can define which column(s) the sort is performed upon, and the sorting direction.
The sort list should contain an tuple for each column to be sorted initially containing the column's index and a direction string ('asc' or 'desc').
type: list
default: []
# tables.py from table import Table from table.columns import Column class PersonTable(Table): id = Column(field='id') name = Column(field='name') class Meta: sort = [(0, 'asc'), (1, 'desc')]
-
Hide search box if False.
type: boolean
default: False
-
Placeholder attribute for search box.
type: unicode
default: u"Search"
-
Hide info label if False.
type: boolean
default: False
-
This string gives information to the end user about the information that is current on display on the page. The
_START_
,_END_
,_TOTAL_
variables are all dynamically replaced as the table display updates, and can be freely moved or removed.type: unicode
default: u"Total
_TOTAL_
" -
Text shown inside the table records when the is no information to be displayed after filtering. sEmptyTable is shown when there is simply no information in the table at all (regardless of filtering)
type: unicode
default: u"No records"
-
Disable paginate if False.
type: boolean
default: False
-
The text to use for pagination 'next' button.
type: unicode
default: u"First"
-
The text to use for pagination 'last' button.
type: unicode
default: u"Last"
-
The text to use for pagination 'previous' button.
type: unicode
default: u"Prev"
-
The text to use for pagination 'previous' button.
type: unicode
default: u"Next"
-
Hide extense button on top-left corner if False.
type: boolean
default: False
-
Template for rending extense button.
type: string
default: None
-
Template name for rending extense button.
type: string
default: None
-
Template context for rendering extense button.
type: dict
default: None
-
A single column of table.
Parameters:
-
field:
For model data source, it is field name that corresponded to the current column. For dict-list data source, use the key instead.
type: string
default: None
-
attrs:
Html attributes for
<td>
tag.Note: For object-related attribute, such as
<td title="xxx">
, use Accessor instance as attribute value. See example below.type: dict
default: None
-
header:
Title text of current column, will rendered as
<th>text</th>
type: string
default: field value
-
header_attrs:
Html attributes for
<th>
elements.type: dict
default: None
-
sortable:
If
False
, this column will not be allowed used for sorting.type: bool
default: True
-
searchable:
If
False
, this column will not be allowed used for searching.type: bool
default: True
-
safe:
If
True
, add safe filter to column string.type: bool
default: True
-
visible:
If
False
, this column will not be included in HTML output.type: bool
default: True
Example:
# tables.py from table import Table from table.columns import Column from table.utils import A class PersonTable(Table): name = Column(field='name', header=u'姓名', attrs={'class': 'custom'}, header_attrs={'width': '50%'}) addr = Column(field='addr', header=u'年龄', attrs={'title': A('addr')}, header_attrs={'width': '50%'})
-
-
Column with hyperlinks that link to another page, such as update, delete.
Parameters:
-
links:
List of Link instance. See class table.columns.Link for more details.
type: Link
default: []
-
delimiter:
Separate links in single column, use SPACE as default.
type: string
default: " "
Example:
# models.py from django.db import models class Person(models.Model): name = models.CharField(max_length=100) # urls.py urlpatterns = patterns('', url(r'^edit/(\d+)/$', 'app.views.edit', name='edit'), ) # tables.py from table import Table from table.utils import A from table.columns import LinkColumn, Link class PersonTable(Table): action = LinkColumn(header=u'操作', links=[Link(text=u'编辑', viewname='edit', args=(A('id'),)),]
Represents a label
<a>
with hyperlink, it will render as<a href="http://example.com">text</a>
Parameters:
-
-
Accept datetime object as column field and format to specific string.
Parameters:
-
format:
See strftime.
type: string
default: "%Y-%m-%d %H:%I:%S"
-
If you want full control over the way the column is rendered, ignore the built-in Columns, and instead place an instance of Column subclass into your Table.