【问题标题】:bootstrap datatable pagination table not working引导数据表分页表不起作用
【发布时间】:2017-06-17 21:59:09
【问题描述】:

引导数据表分页表不工作我做错了什么?我认为文件有问题任何人都可以看到我做错了什么

直播网址是Click here to see live

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css">
<script language="javaScript" src="https://code.jquery.com/jquery-1.12.1.min.js" type="text/javascript"></script>

<script type="text/javascript"  src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
<script language="javaScript" src="https://cdn.datatables.net/plug-ins/3cfcc339e89/integration/bootstrap/3/dataTables.bootstrap.js" type="text/javascript"></script>

<script type="text/javascript" class="init">

jQuery(function($) {
    $('#example').DataTable();

} );

    </script>
<div class="container">
  <div class="row">

            <div class="col-md-12">
<table id="example" class="table table-striped table-bordered display" cellspacing="0" border="1" width="100%">

<script type="text/javascript">
/*
 jQuery(function($) {
 $('#datatable').dataTable();

     $("[data-toggle=tooltip]").tooltip();
  });
*/
</script>




<?php $i = 0; ?>



<?php foreach($data as $entry): ?>



<?php if($i==0){$count = count($entry);} ?> 

    <thead>

<tr>

<?php if($i==0):  ?> 



<?php foreach ($entry as $cell): ?>

<th><?php echo $cell; ?></th>

<?php endforeach; ?> 

</thead>
<tfoot>
                        <tr>
                        <?php foreach ($entry as $cell): ?>
                            <th><?php echo $cell; ?></th>

                            <?php endforeach; ?> 

                        </tr>
                    </tfoot>
<?php else: ?>
<?php

$keys = array_keys($entry,"");

// foreach empty key, we unset that entry
foreach ($keys as $k)
unset($entry[$k]);

?>
    <tbody>
<?php foreach ($entry as $cell): ?>

<td><?php echo $cell; ?></td>

<?php endforeach; ?>     
    <tbody>


<?php endif; ?>

</tr>





<?php $i++; ?>



<?php endforeach; ?>

</table>

</div>
</div>
</div>

问候 数学

【问题讨论】:

  • 你能放一张结果表的图片吗? (提供的链接无效)。

标签: twitter-bootstrap


【解决方案1】:

我仔细查看了您的代码,看起来该表无效,如果该表格式错误,DataTable 插件将无法工作。

在这部分代码中:

<?php if($i==0){$count = count($entry);} ?>
     <thead>
         <tr>
            <?php if($i==0):  ?> 
            <?php foreach ($entry as $cell): ?>
                <th><?php echo $cell; ?></th>
            <?php endforeach; ?> 
     </thead>
     <tfoot>

缺少&lt;/tr&gt;,因此可能会生成无效表。

来自DataTable.net 网站。

要使 DataTables 能够增强 HTML 表格,表格必须是有效的、格式良好的 HTML,带有标题 (thead) 和正文 (tbody)。也可以使用可选的页脚 (tfoot)

  • 提示:最好在加载完 DOM 元素后加载所有 JS,这样做会使页面加载速度更快,页面将完全加载,如果出现 JS 错误,它们将在之后显示。

【讨论】:

  • 这并没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方发表评论。
猜你喜欢
  • 2016-12-21
  • 1970-01-01
  • 2018-03-28
  • 2016-01-11
  • 2017-03-17
  • 2017-10-27
  • 2012-12-05
相关资源
最近更新 更多