A helper to make an HTML table from a list of dicts, objects, or sequences.
A set of CSS styles complementing this helper is in “webhelpers2_grid/html/public/stylesheets/grid.css”. To use them, include the stylesheet in your applcation and set your <table> class to “stylized”.
API¶
-
class
webhelpers2_grid.Grid(itemlist, columns, column_labels=None, column_formats=None, start_number=1, order_column=None, order_direction=None, request=None, url_generator=None, exclude_ordering=None, **kw)¶ This class is designed to aid programmer in the task of creation of tables/grids - structures that are mostly built from datasets.
-
generate_header_link(column_number, column, label_text)¶ This handles generation of link and then decides to call
self.default_header_ordered_column_formatorself.default_header_column_formatbased on whether current column is the one that is used for sorting.
-
-
class
webhelpers2_grid.ObjectGrid(itemlist, columns, column_labels=None, column_formats=None, start_number=1, order_column=None, order_direction=None, request=None, url_generator=None, exclude_ordering=None, **kw)¶ Bw. compatibility object
-
class
webhelpers2_grid.ListGrid(itemlist, columns=None, column_labels=None, *args, **kw)¶ A grid class for a sequence of lists.
This grid class assumes that the rows are lists rather than dicts, and uses subscript access to retrieve the column values. Some constructor args are also different.
If
columnsis not specified in the constructor, it will examineitemlist[0]to determine the number of columns, and display them in order. This works only ifitemlistis a sequence and not just an iterable. Alternatively, you can pass an int to specify the number of columns, or a list of int subscripts to override the column order. Examples:grid = ListGrid(list_data) grid = ListGrid(list_data, columns=4) grid = ListGrid(list_data, columns=[1, 3, 2, 0])
column_labelsmay be a list of strings. The class will calculate the appropriate subscripts for the superclass dict.