Table View

Last Updated: August 10, 2015

class tethys_sdk.gizmos.TableView(rows, column_names='', hover=False, striped=False, bordered=False, condensed=False, editable_columns='', row_ids='', attributes={}, classes='')

Table views can be used to display tabular data. The table view gizmo can be configured to have columns that are editable. When used in this capacity, embed the table view in a form with a submit button.

rows

A list/tuple of lists/tuples representing each row in the table.

Type

tuple or list, required

column_names

A tuple or list of strings that represent the table columns names.

Type

tuple or list

hover

Illuminate rows on hover (does not work on striped tables)

Type

bool

striped

Stripe rows

Type

bool

bordered

Add borders and rounded corners

Type

bool

condensed

A more tightly packed table

Type

bool

editable_columns

A list or tuple with an entry for each column in the table. The entry is either False for non-editable columns or a string that will be used to create identifiers for the input column_fields in that column.

Type

list or tuple

row_ids

A list or tuple of ids for each row in the table. These will be combined with the string in the editable_columns parameter to create unique identifiers for easy input field in the table. If not specified, each row will be assigned an integer value.

Type

list or tuple

attributes

A dictionary representing additional HTML attributes to add to the primary element (e.g. {"onclick": "run_me();"}).

Type

dict

classes

Additional classes to add to the primary HTML element (e.g. "example-class another-class").

Type

str

Controller Example

from tethys_sdk.gizmos import TableView

table_view = TableView(column_names=('Name', 'Age', 'Job'),
                       rows=[('Bill', 30, 'contractor'),
                             ('Fred', 18, 'programmer'),
                             ('Bob', 26, 'boss')],
                       hover=True,
                       striped=False,
                       bordered=False,
                       condensed=False)

table_view_edit = TableView(column_names=('Name', 'Age', 'Job'),
                            rows=[('Bill', 30, 'contractor'),
                                  ('Fred', 18, 'programmer'),
                                  ('Bob', 26, 'boss')],
                            hover=True,
                            striped=True,
                            bordered=False,
                            condensed=False,
                            editable_columns=(False, 'ageInput', 'jobInput'),
                            row_ids=[21, 25, 31])

context = {
            'table_view': table_view,
            'table_view_edit': table_view_edit,
          }

Template Example

{% load tethys_gizmos %}

{% gizmo table_view %}
{% gizmo table_view_edit %}