TableWidget

class visualife.widget.TableWidget(table_id, parent_id, **kwargs)

Bases: object

Creates a new table

Parameters:
  • table_id – ID of a <TABLE> html element
  • parent_id – ID of the outer HTML element this table should be inserted
  • kwargs – see below
Keyword Arguments:
 
  • columns (list(dict)) – provides a list of dictionaries that defines columns of this table. Each dictionary defines a single

    column and must provide at least the two keys: title and field_id

  • data (list(list)) – provides rows of data to be shown in the table; any data[i] element should be a list holding a row of data for this table

  • width (int) – table width - in pixels (300 pixels by default)

  • height (int) – height of the full table, including its header - in pixels (500 pixels by default)

  • header_height (int) – height of the table header - in pixels

  • rows_per_page (int) – the number of rows to be shown on a single page in that table (100 by default)

  • cell_callback (function) – callback routine called when a table cell is clicked. This method will replace the default behavior which is selecting table’s rows by click / shift-click

  • highlight_color (string) – color that will be used to mark rows of this table as selected

Attributes Summary

current_page Provides index of the page of data that is currently displayed by this table browser
data Returns original data that that is displayed by this table.
rows_per_page says how many rows are displayed in this table
selected_rows Provides a list indexes that point to all data rows that are selected

Methods Summary

add_cell_callback(callback_function) Adds an additional callback function that will be called upon a click on a table’s cell
add_column(**kwargs) Adds a new column to this table
add_data_rows(data_rows) Add data rows to this table.
add_page_callback(callback_function) Adds an additional callback function that will be called when user changes a page of this table
add_sort_callback(callback_function) Adds an additional callback function that will be called when this table is sorted by a column
clear_cell_callback() Removes all callback routines assigned to click on a cell events
clear_data() Clears all data of this table.
count_pages() Returns the number of pages the data takes in this table
get_column_data(which_column[, which_page]) Returns data from a column of this table
get_data_row(element_id) Returns a row of data that corresponds to a given ID of a TD or TR page element.
get_data_value(element_id) Returns a data value that corresponds to a given ID of a TD page element.
replace_data(new_data) replaces the data presented by this table with new content; the current data will be lost
select_row(which_row[, if_select]) Selects (or un-selects) a given row of this table
show_table(which_page) Loads a requested page of data into this table
unselect_all_rows() Unselects all rows that are selected

Attributes Documentation

current_page

Provides index of the page of data that is currently displayed by this table browser

Returns:page index from 1 to self.count_pages(), inclusive
data

Returns original data that that is displayed by this table. If this table was sorted by a user, the returned data is in the new order

Returns:original data displayed by this table
rows_per_page

says how many rows are displayed in this table

Returns:number of rows displayed by this table on the screen
selected_rows

Provides a list indexes that point to all data rows that are selected

Methods Documentation

add_cell_callback(callback_function)

Adds an additional callback function that will be called upon a click on a table’s cell

The new callback_function will be called after the already registered callbacks. If you want to replace old callbacks with a new one, call clear_cell_callback() first

Parameters:callback_function – callback function object, which must take a single argument: click event
Returns:None
add_column(**kwargs)

Adds a new column to this table

Parameters:

kwargs – dictionary of properties for that column, see below

Keyword Arguments:
 
  • title (string) – text displayed in the header of this column
  • field_id (string) – ID string for that column
  • format (string) – formatting string for that column, that will be used to convert variable into a string
  • width (string) – CSS string to define the width of this column. Can be like "100px" or "20%"
  • sorter (string) – method used to sort this column, use one of the following: "string", "int" or "float"; use "None" to prohibit sorting by this column
Returns:

None

add_data_rows(data_rows)

Add data rows to this table. This method doesn’t add table rows - the newly added data will not be visible until show_table() is called

Parameters:data_rows – data row (list) or data rows (list[list]) to be added
Returns:None
add_page_callback(callback_function)

Adds an additional callback function that will be called when user changes a page of this table

Parameters:callback_function – callback function object, which must take a single argument: click event
Returns:None
add_sort_callback(callback_function)

Adds an additional callback function that will be called when this table is sorted by a column

The new callback_function will be called after sorting this table; it can be used e.g. to notify that the table content has been altered

Parameters:callback_function – callback function object, which must take a single argument: click event
Returns:None
clear_cell_callback()

Removes all callback routines assigned to click on a cell events

Returns:None
clear_data()

Clears all data of this table.

All data entries will be removed both from internal data structure and from the HTML table. New content may be added with add_data_rows() method

Returns:None
count_pages()

Returns the number of pages the data takes in this table

Returns:the number of pages of this table
get_column_data(which_column, which_page=1)

Returns data from a column of this table

Parameters:
  • which_column – (string or int) points to a column of this table: either its name or index from 0
  • which_page – index that counts from 1 which points to a table page; use which_page=0 to get the whole column (from all pages)
Returns:

list of data from a requested column

get_data_row(element_id)

Returns a row of data that corresponds to a given ID of a TD or TR page element. This method can be used to decode ID of a table element that was clicked by a user into the actual data

stored in this table
Parameters:element_id – (string) ID of an element of a HTML page that displays this table
Returns:row of table’s data or None if the ID was incorrect
get_data_value(element_id)

Returns a data value that corresponds to a given ID of a TD page element. This method can be used to decode ID of a table element that was clicked by a user into the actual data

stored in this table
Parameters:element_id – (string) ID of an element of a HTML page that displays this table
Returns:row of table’s data or None if the ID was incorrect
replace_data(new_data)

replaces the data presented by this table with new content; the current data will be lost

Parameters:new_data – (list(list)) rows of data to be shown in the table; number of data columns should match with the number of columns of this table
Returns:None
select_row(which_row, if_select=True)

Selects (or un-selects) a given row of this table

Parameters:
  • which_row – index of data row to be selected. Note that which_row must not be a table row index
  • if_select – if True (the default), the given row will be selected, if False, the row will be un-selected by this call
Returns:

the resulting state of which_row row of data: True when selected, False otherwise.

Note that the returned value doesn’t tell if this call was successful. E.g. when an attempt was made to select
an already selected row, it returns True (the row is selected) even though the call didn’t change it’s state
show_table(which_page)

Loads a requested page of data into this table

Parameters:which_page – index of a page (counting from 1) to be displayed by this table
Returns:None
unselect_all_rows()

Unselects all rows that are selected