javascript jQuery 数据表:iDisplayLength 设置为 -1 以显示所有行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17271701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Datatables: iDisplayLength set to -1 to show all rows
提问by Sylnois
I use jQuery Datatables and want to listen a Table with all my entries via ajax from a server. Everything works perfectly. I mean, i get the data and can show them in the table. I got only one problem. I want to show all rows/entries at once. I've googled and all say, that i just have to set the iDisplayLength to -1. But if I do that, i got only 1 entrie/row(Showing 1 of 1 of totally 50 entries). Any idea what i'm doing wrong? This is my code to initialize the table:
我使用 jQuery Datatables 并希望通过来自服务器的 ajax 收听包含我所有条目的表。一切正常。我的意思是,我得到数据并可以在表格中显示它们。我只有一个问题。我想一次显示所有行/条目。我用谷歌搜索过,所有人都说,我只需要将 iDisplayLength 设置为 -1。但是如果我这样做,我只会得到 1 个条目/行(显示 1 个共 50 个条目中的 1 个)。知道我做错了什么吗?这是我初始化表的代码:
var oTable = $("#roles").dataTable({
"bServerSide" : true,
"sAjaxSource" : "/data",
"iDisplayLength" : -1,
"aoSearchCols:" ["sSearch" : initiator], null, null, null, null, null, null],
"fnServerParams" : function(aoData){
aoData.push({"name": "sLDAPQuery", "value": "roles"});
}
});
edit: It works, if I set iDisplayLength for example to 1'000, but what if I get more than 1'000 rows?
编辑:它有效,如果我将 iDisplayLength 设置为 1'000,但是如果我得到超过 1'000 行怎么办?
回答by pixelbyaj
I think you first get how many records you are having in the database than dynamically add the length dynamically using fnLengthChange
我认为您首先获得数据库中有多少条记录,而不是使用fnLengthChange动态添加长度
Please click on fnLengthChange. It will show you the example. May it helps you
请单击 fnLengthChange。它将向您展示示例。愿它帮助你