wuttaweb.grids.renderers¶
Grid renderers
- class wuttaweb.grids.renderers.BuefyGridRenderer(request, grid=None, vue_tagname='wutta-grid')[source]¶
Renders the standalone Buefy
<b-table>element.- render_element(template=None, form=None, **context)[source]¶
Render a simple Vue table element for the grid.
This is what you want for a “simple” grid which does not require a unique Vue component, but can instead use the standard table component.
This returns something like:
<b-table :data="gridContext['mykey'].data"> <!-- columns etc. --> </b-table>
Actual output will of course depend on grid attributes,
key,columnsetc.- Parameters:
template – Optional path to custom Mako template.
form – Reference to the
Forminstance which “contains” this grid. This is needed in order to ensure the grid data is available to the form Vue component.**context – Additional context for the template.
- Returns:
HTML literal of the rendered table.
Note
The above example shows
gridContext['mykey'].dataas the Vue data reference. This should “just work” if you provide the correctformarg and the grid is contained directly by that form’s Vue component.However, this may not account for all use cases. For now we wait and see what comes up, but know the dust may not yet be settled here.
- class wuttaweb.grids.renderers.GridRenderer(request, grid=None)[source]¶
Base class and default implementation for grid renderers.
This will render the grid as a simple HTML table, with Bulma classes for styling but no JS or (e.g. Buefy) components involved.
- render_element(template=None, **context)[source]¶
Render the HTML
<table>element.- Parameters:
template – Optional path to custom Mako template.
**context – Additional context for the template.
- Returns:
HTML literal of the rendered table.
- render_mako(template, context)[source]¶
Render a Mako template.
This method exists for sake of non-Pyramid web frameworks to override the final render call. The default logic calls
render()for the Pyramid framework.- Parameters:
template – Path to Mako template.
context – Context dict for the template.
- Returns:
HTML output from rendering the template.
- class wuttaweb.grids.renderers.WuttaGridRenderer(request, grid=None, vue_tagname='wutta-grid')[source]¶
Renders the traditional
<wutta-grid>component, which uses the Buefy<b-table>under the hood.- vue_tagname¶
String name for Vue component tag. By default this is
"wutta-grid". See alsorender_element()andvue_component.
- vue_component¶
String name for the Vue component, e.g.
"WuttaGrid".This is a generated value based on
vue_tagname.
- get_vue_active_sorters()[source]¶
Returns a list of Vue-compatible column sorter definitions.
The list returned is the same as
active_sorters; however the format used in Vue is different. So this method just “converts” them to the required format, e.g.:# active_sorters format {"key": "name", "dir": "asc"} # get_vue_active_sorters() format {"field": "name", "order": "asc"}
- Returns:
The
active_sorterslist, converted as described above.
- get_vue_columns()[source]¶
Returns a list of Vue-compatible column definitions.
This uses
columnsas the basis; each definition returned will be a dict in this format:{ "field": "foo", "label": "Foo", "sortable": True, "searchable": False, }
The full format is determined by Buefy; see the Column section in its Table docs.
See also
get_vue_context().
- get_vue_context()[source]¶
Returns a dict of context for the grid, for use with the Vue component. This contains the following keys:
data- list of Vue-compatible data recordsrow_classes- dict of per-row CSS classes
This first calls
get_visible_data()to get the original data set. Each record is converted to a dict.Then it calls
make_json_safe()to ensure each record can be serialized to JSON.Then it invokes any
rendererswhich are defined, to obtain the “final” values for each record.Then it adds a URL key/value for each of the
actionsdefined, to each record.Then it calls
get_row_class()for each record. If a value is returned, it is added to therow_classesdict. Note that this dict is keyed by “zero-based row sequence as string” - the Vue component expects that.- Returns:
Dict of grid data/CSS context as described above.
- get_vue_filters()[source]¶
Returns a list of Vue-compatible filter definitions.
This returns the full set of
filtersbut represents each as a simple dict with the filter state.
- get_vue_first_sorter()[source]¶
Returns the first active sorter, if applicable.
This method is used to declare the initial sort for a simple table component, i.e. for use with the
table-element.makotemplate. It generally is assumed that frontend sorting is in use, as opposed to backend sorting, although it should work for either scenario.This checks
active_sortersand if set, will use the first sorter from that. Note thatactive_sorterswill not be set unlessload_settings()has been called.Otherwise this will use the first sorter from
sort_defaultswhich is defined in the grid constructor.- Returns:
The first sorter in format
[sortkey, sortdir], orNone.
- get_vue_pager_stats()[source]¶
Returns a simple dict with current grid pager stats.
This is used when
paginate_on_backendis in effect.
- render_element(template=None, **attrs)[source]¶
Render the Vue component tag for the grid.
By default this simply returns:
<wutta-grid></wutta-grid>
The actual output will depend on
vue_tagnameand caller-provided attrs.- Parameters:
template – Optional path to custom Mako template. (This is currently ignored.)
**attrs – Additional HTML attributes for the Vue component tag.
- Returns:
HTML literal for the component tag.
- render_vue_finalize()[source]¶
Render the Vue “finalize” script for the grid.
By default this simply returns:
<script> WuttaGrid.data = function() { return WuttaGridData } Vue.component('wutta-grid', WuttaGrid) </script>
The actual output may depend on various grid attributes, in particular
vue_tagname.
- render_vue_template(template=None, **context)[source]¶
Render the Vue “component” block for the grid.
This is what you want for a “full-featured” grid which will exist as its own unique Vue component on the frontend.
This returns something like:
<script type="text/x-template" id="wutta-grid-template"> <b-table> <!-- columns etc. --> </b-table> </script> <script> WuttaGridData = {} WuttaGrid = { template: 'wutta-grid-template', } </script>Actual output will of course depend on grid attributes,
vue_tagnameetc.- Parameters:
template – Optional path to custom Mako template.
**context – Additional context for the template.
- Returns:
HTML literal containing the Vue script blocks.