I have a table like the following
the table as rowspans because for some users I need to have 2 lines (Like you see at column 'D')
I am trying to use datatables:
<table class="table table-bordered table-hover table-striped" id="myTable">
(...)
</table>
And I call this at the begining of the code:
<script>
$( document ).ready(function() {
$('#myTable').DataTable();
});
</script>
But I have this error:
TypeError: i is undefined
And the table is not like a datatable type!
Maybe it doesn't work with rowspans? Any idea??
I was facing the same issue. The main reason for the error is due to using the colspan & rowspan. Because the jQuery DataTables plug-in does not support them and hence causing the error.
So, If you are using any colspan or rowspan within any
<tr></tr>
inside the<tbody></tbody>
then make sure that each<tr></tr>
having the same no of<td></td>
for each row. If not, then repeat the<td style='display:none'></td>
to match the same no e.gI think by following the above suggestion will help you sure.
I'd say your table is not a data table because you have undefined data and the 'i' referred to is the internal iterator of the DataTable loop, the use of rowspans is the problem - I would redesign your table to have an entire row for each piece of data (in your example 250 would require an entire row with duplicate values for all other columns except D) - it is wholly possible to use css to hide values that are duplicated for the same visual effect, this would allow datatable filtering to still work on those rows (although you may need some hooks to reveal hidden data when these 'extra' rows are filtered).
This problem happens if your table is not well formed, for example you should have
<table>
<thead>
<th>
<tbody>
<tr>
<td>
And then the id of the table should not overlap with id of any thing else on the same page. Other wise you will get errors like i is udefined or c is undefined.
jQuery DataTables plug-in doesn't support
ROWSPAN
attribute by default. However there is a RowsGroup plugin for jQuery DataTables that groups cells together to make them look like as ifROWSPAN
attribute is used.See this example for code and demonstration.
See jQuery DataTables – ROWSPAN in table body TBODY for more details.
FWIW you can also get this error if you don't have the same number of
<td></td>
elements in every row. Make sure you aren't adding any rows with nav buttons or links or anything like that that may not be formatted the same way as the other rows.For future referer.
It is because you are using
Rowspan
orcolspan
which is not supportable.If you want to use colspan you can use it outside
</tbody>
.Thanks.