如何动态更改jQuery Datatables的高度 [英] How to dynamically change jQuery Datatables height
本文介绍了如何动态更改jQuery Datatables的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jQuery 数据表。
每当用户调整窗口大小时,我想更改表的高度。我可以抓住窗口大小事件,让我计算新的高度。如何为datatable对象分配新的高度?
I'm using jQuery Datatables. I want to change the height of the table whenever a user resizes the window. I'm able to catch the window resize event which allows me to calculate the new height. How can I assign the new height to the datatable object?
推荐答案
您可以使用以下代码:
var calcDataTableHeight = function() {
return $(window).height() * 55 / 100;
};
var oTable = $('#reqAllRequestsTable').dataTable({
"sScrollY": calcDataTableHeight();
});
$(window).resize(function() {
var oSettings = oTable.fnSettings();
oSettings.oScroll.sY = calcDataTableHeight();
oTable.fnDraw();
});
这篇关于如何动态更改jQuery Datatables的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文