django tables2 checkbox

情到浓时终转凉″ 提交于 2020-01-24 14:27:04

问题


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?


回答1:


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, … />')



回答2:


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

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


来源:https://stackoverflow.com/questions/15419385/django-tables2-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!