is it possible to use colspan in django tables 2? I have 5 rows with 4 cols, but i want my second row to be with 1 col colspan=4
How can i do this? Is it possible.
Here is my code:
class FavoriteContactTable(FavoriteTable):
date_added = tables.Column()
address = AddressColumn(empty_values=(), orderable=False)
email = tables.EmailColumn(accessor='swimmer.user.email')
phone = PhoneColumn(empty_values=())
class Meta:
model = Favorite
fields = ('address', 'email', 'phone', 'date_added')
attrs = {"class": "table table-condensed table-striped table-hover"}
It is possible to add a colspan
to a Column
with:
tables.Column(attrs={"td": {"colspan": "4"}})
However, this would make all the rows for that column span 4 cells instead of just the second.
Another solution is to override the table template:
class FavoriteContactTable(FavoriteTable):
template = "path_to_template"
It should extend django_tables2/table.html template and then override the table.tbody.row
block.
Probably the easiest solution is to do it with jQuery/Javascript.
$(document).ready(function() {
$(".table > tbody > tr:nth-child(2) > td:nth-child(column_no)").attr("colspan", "4");
});
I haven't checked the Javascript but it should be something along those lines.