I want to select all rows in a table by checking the header checkbox in my CheckBoxColumn.
So far I have tried the following code select all rows in django_tables2 , which works fine for most browsers (e.g. Firefox, Chrome). However, when I open the website with Microsoft Edge and try to select all rows by clicking on the upper checkbox only the first row of the table will be checked, all other rows remain unchecked.
This is my tables.py:
class CRNTable(tables.Table):
LinkModelColumn = tables.CheckBoxColumn(accessor='pk', attrs = {"th__input": {"onclick": "toggle(this)"}}, order_by='pk', verbose_name='Model')
...
This is my JavaScript:
<script language="JavaScript">
function toggle(source) {
var checkboxes = document.getElementsByName('LinkModelColumn');
for(var i in checkboxes){
checkboxes[i].checked = source.checked;}
}
</script>
Aucun commentaire:
Enregistrer un commentaire