gpt4 book ai didi

javascript - Jquery Datatables 不按显示长度过滤行

转载 作者:行者123 更新时间:2023-11-27 23:08:58 24 4
gpt4 key购买 nike

我正在尝试通过 js 数据表显示我的实体。尽管我将 iDisplayLength 设置为 10,但它显示了所有行!

我使用 DataTables 1.10.10

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

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

有谁知道为什么它不起作用。

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

最佳答案

当您使用render函数时,您应该指定列的data

在你的情况下应该看起来像这样......

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

看看这个示例,除了服务器端之外,您有相同的配置

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

更新

请记住,服务器应该为您的分页返回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).

关于javascript - Jquery Datatables 不按显示长度过滤行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36344226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com