2
votes

I'm new to programming so this may be a trivial question...

In django-tables2, I'd like to be able to display the column header name when using CheckBoxColumn. Right now, all the checkboxes are displaying for each row, including in the header. I don't mind having a checkbox in the header (I figure that would be a great way to do a "select all" in the long run), but I need the column name to display. Does anyone have a solution for this?

2
Could you post some code ? - Mehdi Karamosly

2 Answers

1
votes

Create your own custom checkbox column class that inherits from tables.CheckBoxColumn then override the render method, then specify the check box together with its label as html response.

class CustomCheckBoxColumn(tables.CheckBoxColumn):

    def render(self, value, record, bound_column):
        return mark_safe(u'column Name<input type=checkbox, … />')
0
votes

Another option is to use the TemplateColumn() instead of CheckBoxColumn()

template = '<input type="checkbox" name="{{record.name}}" />'
checkbox_column_header = tables.TemplateColumn(template)