TableWidget¶
-
class
visualife.widget.TableWidget(table_id, parent_id, **kwargs)¶ Bases:
objectCreates 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 singlecolumn and must provide at least the two keys:
titleandfield_iddata (
list(list)) – provides rows of data to be shown in the table; anydata[i]element should be a list holding a row of data for this tablewidth (
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 pixelsrows_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-clickhighlight_color (
string) – color that will be used to mark rows of this table as selected
Attributes Summary
current_pageProvides index of the page of data that is currently displayed by this table browser dataReturns original data that that is displayed by this table. rows_per_pagesays how many rows are displayed in this table selected_rowsProvides 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_functionwill be called after the already registered callbacks. If you want to replace old callbacks with a new one, callclear_cell_callback()firstParameters: 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
- title (
-
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 calledParameters: data_rows – data row ( list) or data rows (list[list]) to be addedReturns: 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_functionwill be called after sorting this table; it can be used e.g. to notify that the table content has been alteredParameters: 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()methodReturns: 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 – (
stringorint) 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=0to get the whole column (from all pages)
Returns: listof data from a requested column- which_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 tableParameters: element_id – ( string) ID of an element of a HTML page that displays this tableReturns: row of table’s data or Noneif 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 tableParameters: element_id – ( string) ID of an element of a HTML page that displays this tableReturns: row of table’s data or Noneif 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 tableReturns: 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_rowmust not be a table row index - if_select – if
True(the default), the given row will be selected, ifFalse, the row will be un-selected by this call
Returns: the resulting state of
which_rowrow of data:Truewhen selected,Falseotherwise.- 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
- which_row – index of data row to be selected. Note that
-
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