【问题标题】:django tables2 checkboxdjango tables2 复选框
【发布时间】:2013-03-14 20:19:50
【问题描述】:
我是编程新手,所以这可能是一个微不足道的问题...
在 django-tables2 中,我希望能够在使用 CheckBoxColumn 时显示列标题名称。现在,每一行的所有复选框都显示,包括在标题中。我不介意在标题中有一个复选框(我认为从长远来看,这将是一个“全选”的好方法),但我需要显示列名。有人对此有解决方案吗?
【问题讨论】:
标签:
django
checkbox
header
django-tables2
【解决方案1】:
创建您自己的继承自 tables.CheckBoxColumn 的自定义复选框列类
然后覆盖 render 方法,然后将复选框连同其标签一起指定为 html 响应。
class CustomCheckBoxColumn(tables.CheckBoxColumn):
def render(self, value, record, bound_column):
return mark_safe(u'column Name<input type=checkbox, … />')
【解决方案2】:
另一种选择是使用TemplateColumn() 而不是CheckBoxColumn()
template = '<input type="checkbox" name="{{record.name}}" />'
checkbox_column_header = tables.TemplateColumn(template)