【问题标题】:Datatables - Sorting and search doesn't work数据表 - 排序和搜索不起作用
【发布时间】:2015-11-11 15:00:29
【问题描述】:

我正在使用带有 Ajax 的 jQuery DataTables 来显示数据。它显示数据,但排序和搜索不起作用。当我单击任何列对数据进行排序时,它会显示“正在处理...”,但没有任何反应。

这是我的代码:

<div class="row">
    <div id="flux-col-1" class="col-md-12">
        <div class="body" id="">
            <div class="row">
                    <table id="example" class="display" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th>From</th>
                                <th>Object</th>
                                <th>Date</th>
                            </tr>
                        </thead>

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

<script>

$(document).ready(function() {
    $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "mails",
        "columns": [
                    { "data": "from" },
                    { "data": "object" },
                    { "data": "created" }
                ]
    } );
} );
</script>

【问题讨论】:

  • "ajax": "mails", - 什么是mails
  • “当我点击任何一列过滤数据时”你的意思是排序吗?过滤是从搜索栏完成的。如果您的排序和过滤不起作用,则需要显示您的服务器端代码。这就是使用设置为 true 的“serverSide”选项的本质。您所有的排序、搜索、分页等都是在服务器端代码中完成的。没有它,我们就无法知道问题所在。
  • 尝试删除"serverSide": true。启用服务器端处理后,应在服务器上进行排序、过滤和分页。根据您的描述,您似乎没有使用服务器端处理。

标签: jquery ajax datatables datatables-1.10


【解决方案1】:

试试这个并改变你的“ajax”:“mails”,你的网址是这样的

<div class="row">
    <div id="flux-col-1" class="col-md-12">
        <div class="body" id="">
            <div class="row">
                    <table id="example" class="display" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th>From</th>
                                <th>Object</th>
                                <th>Date</th>
                            </tr>
                        </thead>

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

<script>

$(document).ready(function() {
    $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "<?php echo site_url('mails/ajax_list_mail')?>",

        "columns": [
                    { "data": "from" },
                    { "data": "object" },
                    { "data": "created" }
                ]
    } );
} );
</script>

【讨论】:

    猜你喜欢
    • 2017-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多