Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TableBlock how to specify table CSS classes

I am struggling to add CSS classes to Wagtail StreamField & TableBlock (http://docs.wagtail.io/en/v1.8.1/reference/contrib/table_block.html).

Is the way to go to define a filter and use something like:

{{ child|className:"table table-bordered" }}

where className is my custom filter?

like image 419
Dimitar Petrov Avatar asked Feb 06 '17 15:02

Dimitar Petrov


People also ask

How do you define a class table in HTML?

The class attribute assigns one or more classnames to the <table> tag. Classnames are defined in a stylesheet or in a local <style> element.

What is a table class?

Table class is an implementation of DbTable interface. It uses GDA to get access to a database's table description. In order to load data, you need to set a Gda. Connection and a table's name.


1 Answers

No, this isn't currently possible with the standard rendering of a TableBlock - the template used internally to render the block has hard-coded <table> / <tr> / <td> tags with no class attributes. However, you could specify a custom template in your TableBlock declaration, which would give you full control over the HTML:

StreamField([
    # ...
    ('table', TableBlock(template='/path/to/custom/template.html')),
    # ...
])
like image 183
gasman Avatar answered Sep 19 '22 17:09

gasman