如何为此div设置合适的宽度?

时间:2014-01-29 16:37:04

标签: jquery html html-table width

我正在构建一个个性化的表格,我想用固定标题进行滚动。我创建了一个div,它将替换原始的header表并将被修复。

我做了一个简单的JS函数:

function resizeCol(numerocolonne){

var leng= $("tbody tr").length;
for(i=1;i<=numerocolonne; i++){
    var bigger=$('[value="1-'+i+'"]').width();
    $('[value="0-'+i+'"]').width(bigger);
}

}

计算列的 width 并设置假标题的宽度。一切都很好,除了我不知道如何正确地整理假的标题列和真正的标题列。

我不知道我是否清楚地解释了自己,所以这里有一个小提琴:

FIDDDLE

我无法使 #header div比窗口宽。

1 个答案:

答案 0 :(得分:0)

我已经开始了这个:

resizeCol(14);


function resizeCol(numerocolonne){
    $('#datatable_pagament_invisibile thead').clone().appendTo('#header');
    var $headers = $('#datatable_pagament_invisibile th');
    $headers.each(function(index, el) {
        $('#header').width($('#datatable_pagament_invisibile').width());
        //$('#header thead th').height($('#datatable_pagament_invisibile thead').height());
        $('#header th').eq($headers.index(this)).width($(this).width());
    });
}

它采用了与你正在做的不同的方法(主要是因为你做它的方式无论如何都需要类似的工作) - 它克隆thead并将它放在另一个div中,然后模仿表的宽度和列。

Fiddle here

你可能也对another solution that I found posted in another similar question.感兴趣我会选择这个,如果适合你的情况/代码。我认为这是一个更简单,更清洁的解决方案。

相关问题