带有DataTable的动态HTML表格未分页

时间:2017-01-30 19:16:38

标签: javascript php jquery pagination datatables

我有一个以下列结构生成的html表:

echo "<table class='table table-striped table-inverse table-bordered table-hover' id='LeaderBoardTable' table_Dynamic >";
echo "<thead>";
echo "<tr>";
echo "<th></th>";
echo "<th>Username</th>";
echo "<th>SteamID</th>";
echo "<th>Score</th>";
echo "<th>K/D</th>";
//echo "<th>Search</th>"; //Do later
echo "</tr>";
echo "</thead>";
echo "<tbody id='leaderboardTable' class='leaderboardTable'>";
foreach ($items as $item){
    $player = new Player($item['steam'], $dbh);
    echo "<tr>";
    echo "<td><i class='fa fa-crosshairs' aria-hidden='true'></i></td>";
    echo "<td>" . $player->get("name") . "</td>";
    echo "<td>" . $player->get("steam") . "</td>";
    echo "<td>" . $player->get("score") . "</td>";
    echo "<td>" . getKD($player) . "</td>";
    echo "</tr>";
} 
echo "</tbody>\n</table>";

表格加载正常,javascript将其插入文档中,如下所示:

$(document).ready(function() {
    $.ajax({
        type: 'post',
        url: 'control/leaderboard/leaderboardGrab.php',
        data: 'null=null',
    }).done(function(d){
        $('#loadArea').html(d);
        $('#LeaderBoardTable').DataTable({
            "order": [[3, "desc"]],
            "bPaginate": true,
        });
    });

});

表格本身加载正常,.DataTable()函数“正常”,因为表中有旁边的箭头进行排序,搜索框和显示的项目数都在那里并且完美地工作但是分页确实虽然它确实出现并显示正确的页数,但似乎不起作用。目前它显示[1] [2] [3] [4] [5] [...] [307]所以它确实有适量的页面,但我无法点击任何数字去那页。下面是调用生成代码的完整页面,以及所有文件调用。

<html>
<head>
    <title> <?php echo $webTitle; ?> </title>
    <?php $page = "leaderboards" //setting page for include ?>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Calling JS -->
    <!-- Latest compiled and minified Jquery JavaScript -->
    <script src="js/jquery.min.js"></script>
    <script src="js/DataTable/jqueryDataTables.js"></script>
    <script src="js/DataTable/dataTables.bootstrap4.min.js"></script>
    <script src="js/bootstrap/bootstrap.min.js"></script>
    <script src="js/leaderboard/leaderboardFunctions.js"></script>
    <!-- Bootstrap 4 and Tether -->
    <script src="js/tether/tether.min.js"></script>

    <!-- Custom JS -->
    <script src="js/Navjs.js"></script>
    <script src="js/paging.js"></script>

    <!-- End Of JS -->

    <!-- Bootstrap 4, Tether, Fontawesome -->
    <link rel="stylesheet" href="css/DataTable/dataTables.bootstrap4.css">
    <link rel="stylesheet" href="css/tether/tether.min.css">
    <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css">
    <link rel="stylesheet" href="css/fontawesome/font-awesome.min.css">
    <link rel="stylesheet" href="css/social.css">
    <!-- Custom CSS --> 
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include_once "views/social.php" ?>
<div class="container" style="width:95%;">
    <div class="row">
        <div class="wrapper">
            <?php include_once "views/nav/index.php" ?>

            <?php include_once "views/$page/index.php" ?>
        </div>
    </div>
</div>

</body>
</html>

为什么它不起作用的任何想法? 90%的DataTables正在运行,但分页不起作用,而且看起来是唯一不起作用的部分。

我得到的仅有控制台错误缺少Favicon.ico。

谢谢!

1 个答案:

答案 0 :(得分:0)

对我所包含的文件进行了一些更改,我尝试使用CDN,除了一些样式之外它主要工作,所以我下载了与CDN和jquery-ui相同的文件并添加并且似乎正在工作。