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

NaveenVarmaNaveenVarma Posts: 4Questions: 2Answers: 0
edited July 26 in Free community support
        <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

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Error: Datatable is taking inly first row after heading.

    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

  • allanallan Posts: 63,262Questions: 1Answers: 10,423 Site admin

    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 one tbody element as well.

    Allan

Sign In or Register to comment.