更改 jquery 数据表显示的默认行数

发布于 2025-01-05 01:48:32 字数 194 浏览 0 评论 0原文

默认情况下,数据表有 4 种大小的记录显示:10、25、50、100。

A)有办法改变这个吗?我尝试编辑 jquery 文件以将数组更改为 [30,60,90,120] 本身,但这破坏了它。

B) 有没有办法在 jquery 构建时初始化时将此选择器的默认选择大小设置为 50(而不是 10)?

我在文档中找不到这些项目。

By default, datatables has 4 sizes of records to show: 10,25,50,100.

A) Is there a way to change this? I tried editing the jquery file to change the array to [30,60,90,120] itself and this destroyed it.

B) Is there a way to set the default selection size say to 50 (instead of 10) of this selector upon initializing when jquery builds it?

I can't find either of these items in the documentation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧竹 2025-01-12 01:48:33

数据表版本:1.9.4
对我有用的是:-
首先,我搜索了 Jquery.dataTables 文件,该文件主要位于 js 文件夹中。然后我搜索“aLengthMenu”:[10,25,50,100],并根据我的要求进行更改,即“aLengthMenu”:[50,75,100,125]。此后,我搜索“iDisplayLength”,只要其值显示为 10(4 到 5 个位置),我将其更改为 50 并保存。我的索引页面上的下拉列表开始将行选项显示为 50,75,100,125,而不是 10,25,50,100,默认选项选择为 50。

Datatable Version : 1.9.4
What works for me is this:-
First I searched the Jquery.dataTables file which is mostly placed in the js folder. Then I search for "aLengthMenu": [ 10, 25, 50, 100 ], and changed it according to my requirements i.e. "aLengthMenu": [ 50, 75, 100, 125 ]. Thereafter I searched for "iDisplayLength" and wherever its value is shown as 10 (4 to 5 places), I changed it to 50 and save. Dropdown on my index page started showing row option as 50,75,100,125 in place of 10,25,50,100 with default option selected as 50.

怀里藏娇 2025-01-12 01:48:32

[更新,因为这个答案似乎得到了一些意见] -

更新答案:

在更高版本(我相信1.10+)中,API命名约定发生了变化,放弃了匈牙利表示法。我相信旧的约定是为了兼容性而使用别名,但当前的约定是:

lengthMenu
pageLength

因此,更新的答案是:

A)它是 lengthMenu 参数:https://datatables.net/reference/option/lengthMenu

例如,以下是我的一组设置:

"lengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "All"]],

B) pageLength https://datatables.net/reference/option/pageLength -- 可以选择将其设置为默认值是。

"pageLength" : 25,

原始答案

A)这是aLengthMenu参数:http:// datatables.net/ref#aLengthMenu

例如,以下是我的一组设置:

"aLengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "All"]],

B) iDisplayLength -- 将此参数设置为默认值

[Update because this answer seems to get some views] --

Updated Answer:

In later versions (I believe 1.10+), the API naming conventions changed, ditching the Hungarian notation. I believe the old conventions are aliased for compatibility, but the current conventions are:

lengthMenu
pageLength

Thus, the updated answers are:

A) it's the lengthMenu parameter: https://datatables.net/reference/option/lengthMenu

For example, here's how I have one of mine set:

"lengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "All"]],

B) pageLength https://datatables.net/reference/option/pageLength -- optionally set this to whatever your default should be.

"pageLength" : 25,

Original Answer

A) It's the aLengthMenu parameter: http://datatables.net/ref#aLengthMenu

For example, here's how I have one of mine set:

"aLengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "All"]],

B) iDisplayLength -- set this parameter to whatever your default should be

╰◇生如夏花灿烂 2025-01-12 01:48:32
  • 数据表 1.10+

    使用 lengthMenu 定义可用页面长度列表和可选 pageLength 设置初始值页长。

    如果未指定pageLength,则会自动指定设置为 lengthMenu 指定的数组中给定的第一个值。< /p>

    var table = $('#example').DataTable({
       lengthMenu: [ [2, 4, 8, -1], [2, 4, 8, "全部"] ],
       页长:4
    });
    

    请参阅此 jsFiddle 以获取代码和演示。


  • 数据表 1.9

    使用aLengthMenu定义可用页面长度的列表和< a href="http://legacy.datatables.net/usage/options#iDisplayLength" rel="nofollow noreferrer">iDisplayLength 设置初始页面长度。

    var table = $('#example').dataTable({
       "aLengthMenu": [ [2, 4, 8, -1], [2, 4, 8, "全部"] ],
       “iDisplayLength”:4,        
    });
    

    请参阅此 jsFiddle 以获取代码和演示。

  • DataTables 1.10+

    Use lengthMenu to define a list of available page lengths and optionally pageLength to set initial page length.

    If pageLength is not specified, it will be automatically set to the first value given in array specified by lengthMenu.

    var table = $('#example').DataTable({
       lengthMenu: [ [2, 4, 8, -1], [2, 4, 8, "All"] ],
       pageLength: 4
    });
    

    See this jsFiddle for code and demonstration.


  • DataTables 1.9

    Use aLengthMenu to define a list of available page lengths and iDisplayLength to set initial page length.

    var table = $('#example').dataTable({
       "aLengthMenu": [ [2, 4, 8, -1], [2, 4, 8, "All"] ],
       "iDisplayLength" : 4,        
    });
    

    See this jsFiddle for code and demonstration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文