选择django_tables2中的所有行 [英] select all rows in django_tables2
本文介绍了选择django_tables2中的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过单击具有以下定义的CheckBoxColumn中的上部复选框来选择表中的所有行:
I have tried to select all rows in a table by clicking on the upper check box in a CheckBoxColumn with the following definition:
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
但是行没有被选中,我还有什么需要做的吗?我正在使用django 1.4.1和django_tables2 0.13.0。
However the rows are not selected, is there anything else I need to do? I am using django 1.4.1 and django_tables2 0.13.0.
推荐答案
可以通过替换来选择CheckBoxColumn中的所有复选框标题单元格中的输入属性:
It is possible to select all checkboxes in a CheckBoxColumn by replacing the input attribute in the header cell:
selection = tables.CheckBoxColumn(accessor="pk", attrs = { "th__input":
{"onclick": "toggle(this)"}},
orderable=False)
然后,模板文件中的此JavaScript构造应完成工作。
Then this JavaScript construct in the template file should do the work.
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('selection');
for(var i in checkboxes)
checkboxes[i].checked = source.checked;
}
</script>
这篇关于选择django_tables2中的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文