简体   繁体   English

Jquery 数据表不按显示长度过滤行

[英]Jquery Datatables doesn't filter rows by displaylength

I am trying to show my entities via js datatables.我正在尝试通过 js 数据表显示我的实体。 Altough i set iDisplayLength as 10 it shows all the rows!尽管我将 iDisplayLength 设置为 10,但它显示了所有行!

I use DataTables 1.10.10我使用数据表 1.10.10

JS: JS:

var settings = {
        bAutoWidth: false,
        autoWidth: false,
        serverSide: true,
        processing: true,
        bLengthChange: true,
        iDisplayLength: 10,
        destroy: true,
        scrollCollapse: true,
        bLengthChange: true,
        ajax: {
            url: '/service/op',
            type: 'POST',
            dataSrc: 'data.posts',
            data: function (d) {
                d.op = 'datatable';
                d.sub_op = '@table_api';
                return JSON.stringify(d)
            }
        },
        sDom: "<'table-responsive't><'row'<p i>>",
        columns: [
            {
                render: function (data, type, link) {
                    return "shitttt"
                }
            }
        ],

    };

    var dt = $("#table-@current_page").DataTable(settings);

HTML HTML

<div class="row">
    <div class="col-md-10 col-vlg-7">
        <table class="monitoring_timeline" id="table-@current_page">
            <thead>
                <tr>
                    <th></th>
                </tr>
            </thead>
            <tbody>

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

Does anyone know why it doesn't work.有谁知道为什么它不起作用。

JSON: JSON:

{
    "draw": 1,
    "recordsTotal": 1515,
    "recordsFiltered": 1,
    "data": {
        "posts": [{
            "id": -7840784480314929507,
            "datetime": "\/Date(1459359970000)\/",
            "day_str": "today",
            "time_str": "10.00 pm",
            "user_name": "Clarice",
            "user_profile_pic": "http://pbs.twimg.com/profile_images/714612662265651200/pbe_pnec_normal.jpg",
            "sentiment": 2,
            "title": "N tem nd pior q criar expectativas e se decepcionar!!! Arrrgh",
            "content": "N tem nd pior q criar expectativas e se decepcionar!!! Arrrgh",
            "lang": "pt",
            "media": false,
            "media_type": 0,
            "media_src": null,
            "iframe": false,
            "comments": null,
            "reactions": null,
            "reposts": null,
            "crm": false,
            "topic": 0,
            "category": {
                "1": 1,
                "2": 2,
                "3": 1
            }
        }, {
            "id": -3529972708747955425,
            "datetime": "\/Date(1459359970000)\/",
            "day_str": "today",
            "time_str": "10.00 pm",
            "user_name": "Um tal de Fernando",
            "user_profile_pic": "http://pbs.twimg.com/profile_images/714705253191561216/Gn64mC-l_normal.jpg",
            "sentiment": 2,
            "title": "1 mês que não sei o que é escola",
            "content": "1 mês que não sei o que é escola",
            "lang": "pt",
            "media": false,
            "media_type": 0,
            "media_src": null,
            "iframe": false,
            "comments": null,
            "reactions": null,
            "reposts": null,
            "crm": false,
            "topic": 0,
            "category": {
                "1": 1,
                "2": 2,
                "3": 1
            }
        }]
    }
}

When you use render function, you should specified the data of column.使用render功能时,应指定列的data

In your case should look something like this....在你的情况下应该看起来像这样......

columns: [
           {
            data : "op",
            render: function (data, type, link) {
                return "shitttt"
            }
         ]

check out this example, you have your same configuration, except the server side看看这个例子,你有相同的配置,除了服务器端

Example: https://jsfiddle.net/cmedina/7kfmyw6x/34/示例: https : //jsfiddle.net/cmedina/7kfmyw6x/34/

UPDATE更新

Remember that the server should return recordsFiltered for your pagination!请记住,服务器应该为您的分页返回记录recordsFiltered

"draw": 1,
"recordsTotal": 1515,
"recordsFiltered": 1,//Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned for this page of data).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM