B. TIger
B. TIger

Reputation: 560

Datatable plugin not working on html table

I was using a plugin previously for pagination that was jQuery paginate but since it was just limited to pagination I decided to switch to the one at http://datatables.net but when I apply it just like the tutorial says to it appears a line sayng that there is No data available in table, and that is Showing 0 to 0 of 0 entries here is my html and how Im trying to sort this out

<%@ include file="/template/jstl.jsp"%>
<html>
<title></title>
<head>
<script type="text/javascript" src="${ctx}/js/jquery/jquery-1.7.2.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery/jPaginate.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery/jquery.dataTables.js"></script>
<script type="text/javascript" src="${ctx}/js/device/device.js"></script>

</head>
<body>

<div class="titulo">Lista de Dispositivos</div>
    <table class="device" id="table_id">
        <thead>
            <tr>
                <th >Nome</th>
                <th >Código</th>
                <th >Ações</th>
                <th >Excluir</th>

            </tr>
        </thead>
        <tbody>
            <c:if test="${empty devices}">
                <tr>
                    <td colspan="4" align="center">                             
                         Nenhum dispositivo encontrado</td>
                </tr>
            </c:if>

        </tbody>
        <tbody id="tableholder" class="classholder">
        <c:forEach var="device" items="${devices}">
            <tr>
                <td><a href="<c:url value="/device/update/${device.id}"/>">${device.name}</a></td>
                <td><a href="<c:url value="/device/update/${device.id}"/>">${device.code}</a></td>
                <td><a href="<c:url value="/comandos/${device.id}"/>"><img src="${ctx}/images/comandos.png" alt="Comandos" title="Comandos"></a></td>
                <td><a id="${device.id}" class="delete" href="#"><input type="submit" id="excluir_button" value="" title="Excluir" /></a></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

</body>
</html>

and here is my JavaScript

jQuery(document).ready(function () {
    jQuery("#table_id").dataTable(); 
});

Upvotes: 0

Views: 2215

Answers (1)

davidkonrad
davidkonrad

Reputation: 85578

DataTables does not support multiple <tbody>-tags. Furthermore, your first <tbody> contains only one column spanning four, which not match the <thead>-section, and therefore DataTables fails its initialization. DataTables does not understand colspanning.

Also, why both jquery.dataTables.min.js and jquery.dataTables.js?

Upvotes: 1

Related Questions