Base Column and ColumnGroup¶
- class webgrid.Column(*args, **kwargs)[source]¶
Column represents the data and render specification for a table column.
- Args:
label (str): Label to use for filter/sort selection and table header.
key (Union[Expression, str], optional): Field key or SQLAlchemy expression. If an expression is provided, column attempts to derive a string key name from the expression. Defaults to None.
filter (FilterBase, optional): Filter class or instance. Defaults to None.
can_sort (bool, optional): Enables column for selection in sort keys. Defaults to True.
xls_num_format (str, optional): XLSX number/date format. Defaults to None.
render_in (Union(list(str), callable), optional): Targets to render as a column. Defaults to _None.
has_subtotal (Union(bool,str,callable), optional): Subtotal method to use, if any. True or “sum” will yield a sum total. “avg” maps to average. Can also be a callable that will be called with the aggregate expression and is expected to return a SQLAlchemy expression. Defaults to False.
visible (Union(bool, callable), optional): Enables any target in render_in. Defaults to True.
group (ColumnGroup, optional): Render grouping under a single heading. Defaults to None.
- Class Attributes:
xls_width (float, optional): Override to autocalculated width in Excel exports.
xls_num_format (str, optional): Default numeric/date format type.
- extract_and_format_data(record)[source]¶
Extract a value from the record for this column and run it through the data formaters.
- format_data(value)[source]¶
Use to adjust the value extracted from the record for this column. By default, no change is made. Useful in sub-classes.
- new_instance(grid)[source]¶
Create a “copy” instance that is linked to a grid instance.
Used during the grid instantiation process. Grid classes have column instances defining the grid structure. When the grid instantiates, we have to copy those column instances along with it, to attach them to the grid instance.
- render(render_type, record, *args, **kwargs)[source]¶
Entrypoint from renderer.
Uses any renderer-specific overrides from the column, or else falls back to the output of extract_and_format_data.
Renderer-specific methods are expected to be named render_<type>, e.g. render_html or render_xlsx.
- property render_in¶
Target(s) in which the field should be rendered as a column.
Can be set to a callable, which will be called with the column instance.
- Returns:
tuple(str): Renderer identifiers.
- property visible¶
Enables column to be rendered to any target in render_in.
Can be set to a callable, which will be called with the column instance.
- Returns:
bool: Enable render.