【问题标题】:Pagination not showing and not working in DataTables分页未显示且在 DataTables 中不起作用
【发布时间】:2016-04-20 06:33:19
【问题描述】:

在解决了另一个让读取数据库的 php 代码正常工作的问题后,发现这是我自己的错误,即服务器文档根目录中没有 html,我很犹豫要不要问这个问题,但这里是:

我正在显示包含的 jQuery 模块和 css 模块的标题列表。我得到了前 10 行数据,这 10 行是可排序的,但只有那 10 行。我无法显示分页按钮,也无法显示其他行,即使我将数字设置为 25,也只有 10 显示.

 <title>My Library</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css"/>
    <LINK REL="stylesheet" HREF="_css/jquery.dataTables_themeroller.css" />
    <LINK REL="stylesheet" HREF="_css/home.css" id="styleid"/>
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/demo/demo.css">
     <script type="text/javascript" class="init">
        $(document).ready(function() {
            $('#books').DataTable({
            processing: true,
            bStateSave: true,
            ajax: {
                url: "./get_books.php",
                dataSrc: "data"
            },
            columns: [
                { data: "id" },
                { data:  "author" },
                { data:  "title" },
                { data:  "genre" },
                { data:  "location" },
                { data: "notes" }
            ]
            });
            $(document).on('click','#books tbody tr',function() {
                var row = $(this).closest("tr");
                //alert("You clicked: "+$(row).find("td:nth-child(6)").text());
                editBook($(row).find("td:nth-child(1)").text(),$(row).find("td:nth-child(2)").text(),$(row).find("td:nth-child(3)").text(),$(row).find("td:nth-child(4)").text(), $(row).find("td:nth-child(5)").text(), $(row).find("td:nth-child(6)").text());
            });
        });
    </script>

home.css 设置一些默认颜色。我正在使用 easyui 弹出输入和编辑表单。这似乎奏效了。

【问题讨论】:

    标签: jquery html css pagination datatables


    【解决方案1】:

    如果您从 previous question 使用 PHP,它将始终返回 10 行,因为 jQuery DataTables 不发送 rows 参数。

    改用来自my answer 的 PHP 代码。

    【讨论】:

    • 就是这样!对不起,但是当你得到一个例子时,你并不完全理解它,那么就很难找到明显的。我将它限制为 10 行,并且始终相同 10。一件事,在添加一行然后从数据库重新加载之后,新行不存在。但是,如果我刷新页面,它就会显示出来。
    • 也想出了这个。我不是以某种方式指的是同一张桌子。在文档准备好之前,我添加了一个 var oTable = $(#books).DataTables... 。然后在我用 sql 做任何事情的地方,我跟着 oTable.ajax.reload(null, false);这解决了问题。不知道为什么 $(#books).ajax.reload(null, false) 不起作用,但确实如此。
    猜你喜欢
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多