I've a problem using DataTables. When i add colspan for the last column, the datatable plugin wont get applied to the table. If i remove the colspan for the last one and put it to any other column, it works.
For example -
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="stu_data_table">
<thead>
<tr>
<th> </th>
<th colspan="2"> </th>
<th colspan="2"> </th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
$('#stu_data_table').dataTable({
});
Any solution for this?
dataTable does not support colspan or rowspan.
If you use a colspan, dataTable won't understand the columns count / calculation, returning undefined and throwing an error in that case.
So what we need to do, is tell dataTable that in case it doesn't get the expected result, what should be the alternative one.
For that we will use: defaultContent property, and of course expecifying the targets / affected columns.
For example: on a table with 3 td's if we use td colspan="2", we will have to set the default values for the other 2 (because one already exists - and it's the first).
Code:
An alternative method is to use
Child rows
. This will eventually add a row below the parent as shown in the picture belowCode
DataTables doesn't support colspans like you're using them. Follow their complex header example instead.
Your equivalent would look something like this: