javascript jquery - 数据表更改 sScrollY

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14685865/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 22:19:14  来源:igfitidea点击:

jquery - datatable change sScrollY

javascriptjquerydatatable

提问by nagy.zsolt.hun

I would like to change size of scrollable area of a datatable.

我想更改数据表的可滚动区域的大小。

$('#example').dataTable({"sScrollY": 100});
//some stuff..
$('#example').dataTable({"sScrollY":101}); //wrong: cannot reinitialize

采纳答案by nagy.zsolt.hun

$('.dataTables_scrollBody').css('height', 400);

回答by Neo

To change the Y Scroll use the below code,

要更改 Y 滚动,请使用以下代码,

var objDataTable = $('#example').dataTable({"sScrollY" : 100});
objDataTable.fnSettings().oScroll.sY = 101;
objDataTable.fnDraw();

回答by Carlos Cuesta

If yoy have several datatables you can access each by the wrapper:

如果 yoy 有多个数据表,您可以通过包装器访问每个数据表:

$('#example').dataTable({'sScrollY': 100});
//some stuff..
objDataTable.fnSettings().oScroll.sY = '225px';
$('#example_wrapper').children('.dataTables_scroll').children('.dataTables_scrollBody').css('height', '225px');

回答by Alberto Gaona

For jquery.dataTables 1.10.x :

对于 jquery.dataTables 1.10.x :

$('div.dataTables_scrollBody').height( 400 );

This is the recommended way according to Datatables documentation. According to the same documentation the use of the settings object is discouraged as it is internal.

这是根据 Datatables 文档推荐的方式。根据相同的文档,不鼓励使用设置对象,因为它是内部的。

回答by user1883793

I had to combine both to solve my problem. In my case I want to do endless pagination, the problem is that after window resize, the height of dataTables_scrollBody stay fixed, so I have to adjust the oScroll to show the table data with scrolling bar. Setting the dataTables_scrollBody height will work when window size change, but after table redraw it will roll back using the old sScrollY value, and Neo's code fixed this. :)

我不得不结合两者来解决我的问题。在我的情况下,我想做无休止的分页,问题是在调整窗口大小后,dataTables_scrollBody 的高度保持不变,所以我必须调整 oScroll 以显示带有滚动条的表格数据。设置 dataTables_scrollBody 高度会在窗口大小改变时起作用,但在表格重绘后它将使用旧的 sScrollY 值回滚,Neo 的代码修复了这个问题。:)

objDataTable.fnSettings().oScroll.sY = 101;
objDataTable.fnDraw();
$('.dataTables_scrollBody').css('height', 400);