Complex headers with multiple rows problems
Complex headers with multiple rows problems
First of all I'm using Datatables v1.13.11, which I know is quite old.
I have a table that has 3 header rows
1. A row with one th that spans the entire table
2. A row with multiple th elements, some of which span multiple columns as a sort of group header. Some of these th have a row span and span this row and the next.
3. A row with one th element for each column, some of which don't contain any text as they are icon columns or something, some of which have text as a sub header
I'm able to iterate over each column and grab each header with table.column(index).header() and then get the text in that header with innerHTML.
I have issues with the columns that are a sub header (colspan=1, third row). In this case I want to get the text from the 'group' header.
Is there any way for me to do this with datatables? My end goal is sort of group these columns together programmatically so that I can hide them all together.
I am aware of sortCellsTop - this helps with th elements that are the only element in their 'group'.
I am also aware of passing in a row index into header(), or title(), but that is only available with Datatables 2 afaik.
Would appreciate any help, thanks.
This question has an accepted answers - jump to answer
Answers
Datatables 1.x only knows about one header row either the bottom by default or the top if
orderCellsTop
is enabled. More details can be found in this 1.x complex header example. There are no API's in Datatables to access the other header rows. In this case you will need to use standard Javascript or jQuery methods to access the header elements.Or upgrade to 2.x which
column().header()
has additional support for a header row number.Kevin