数据表 - 排序和搜索不起作用

Datatables - Sorting and search doesn't work

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

这是我的代码:

<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" 改成这样 URL

<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>