如何动态更改 jQuery 数据表的高度 [英] How to dynamically change jQuery Datatables height

查看:28
本文介绍了如何动态更改 jQuery 数据表的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jQuery 数据表.每当用户调整窗口大小时,我都想更改表格的高度.我能够捕捉到窗口调整大小事件,它允许我计算新的高度.如何将新高度分配给数据表对象?

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 数据表的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆