DataTable not working when using jstl tags in jsp- showing only first row
DataTable not working when using jstl tags in jsp- showing only first row
NaveenVarma
Posts: 4Questions: 2Answers: 0
<link rel='stylesheet' href='https://cdn.datatables.net/2.1.2/css/dataTables.dataTables.min.css'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/2.1.2/js/dataTables.min.js"></script>
<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {$('#table_id').dataTable({'iDisplayLength': 100,
"bFilter": true,
"bPaginate" : true,
"bInfo": true,
});
});
</script>
<table class="responsive-table" id="table_id">
<c:forEach var="detail" items="${data}" varStatus="itr">
<c:if test="${itr.first}">
<thead>
<tr class= "row-label tr-spl2-bc">
<c:forEach var="det" items="${detail}">
<th scope="col">
${det}
</th>
</c:forEach>
</tr>
</thead>
</c:if>
<c:if test="${!itr.first}">
<tbody>
<tr class="row-value tr3-bc">
<c:forEach var="det" items="${detail}">
<td scope="row" align="left" style="font-size: 12px;font-weight: bold">
${det}
</td>
</c:forEach>
</tr>
</tbody>
</c:if>
</c:forEach>
</table>
Error: Datatable is taking inly first row after heading.
Please guide me.
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
When you say "first row" do you mean that only the first row is part of the DataTable, and all the other rows are just standard HTML? If so, that would suggest you're initialising the table before you've finished drawing the page.
Colin
I'd suggest you "View source" on your generated page. You should have one and only one
thead
element in the table, and one and only onetbody
element as well.Allan