django tables2复选框 [英] django tables2 checkbox

查看:184
本文介绍了django tables2复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始编程,所以这可能是一个小问题。

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

在django-tables2,我想能够显示列使用CheckBoxColumn时的头名称。现在,所有复选框都显示每一行,包括在标题中。我不介意在标题中有一个复选框(我认为这将是一个伟大的方法来做一个选择所有在长期),但我需要列名称显示。有人有解决方案吗?

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?

推荐答案

创建自己的自定义复选框列类继承自tables.CheckBoxColumn
然后重写render方法,然后指定复选框及其标签作为html响应。

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

这篇关于django tables2复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆