简体   繁体   English

如何使用JavaScript / Jquery调整跨两个HTML表的表列的大小

[英]How to resize table columns spanning across two HTML table using JavaScript/Jquery

I want to add column resize functionality to my html table. 我想向我的html表添加列大小调整功能。 User should be able to resize column at runtime . 用户应该能够在运行时调整列的大小 I looked at various examples and plugins but they all work when you have a single table. 我看了各种示例和插件,但是当您只有一个表时它们都可以工作。 Where Table header and table body both are part of same table tag, like this: 其中表标头和表主体都是同一table标签的一部分,如下所示:

<table width="100%" >
    <tr> <th> header </th> <th> header </th> </tr>
    <tr> <td> cell </td> <td> cell </td> </tr>                          
    <tr> <td> cell </td> <td> cell </td> </tr>                          
  </table>  

I am using Jquery DataTable which renders table in two parts. 我正在使用Jquery DataTable ,它分两部分呈现表格。 Column Header is part of one table and body is part of another table. 列标题是一个表的一部分,主体是另一表的一部分。 See the attached image for more information. 有关更多信息,请参见所附图像。 在此处输入图片说明

How can I add column resize functionality in such case? 在这种情况下,如何添加列大小调整功能?

Icing on the cake : I need to support IE 8. 锦上添花:我需要支持IE 8。

With datatables you set the columns like so 使用数据表,您可以像这样设置列

$('#example').dataTable( {
  "columns": [
    { "width": "20%" },
    null,
    null,
    null,
    null
  ]
} );

Which sets the width of the first column and leaves the other columns auto. 设置第一列的宽度,其他列保持自动。 You may need to redraw the table after changing the width if you do it after initialization though. 但是,如果在初始化后进行更改,则可能需要在更改宽度后重新绘制表格。

$('#example').DataTable().columns.adjust().draw();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM