2011-09-02 65 views
4

感谢阅读。我有一个div容器(div0)内的表格。该表格填充了数据并且是动态生成的。所以表格的高度和宽度不固定。外部div可以垂直滚动和水平滚动来查看整个表格。现在要求我需要水平排列第一列的位置,即在滚动水平滚动条时,第一列应该是固定的,而其余的应该是滚动的。只需要一些关于此的指针,关于如何实现这个?制作固定在水平卷轴上的第一列表格

我想分隔div(div1)中的第一列内容(不可水平滚动),以及其他可滚动的分隔div(div2)中的内容都放置在表中一行和2个tds。现在我得到2 probs这种方法,1 div 2的滚动条进入div0时,当我向右滚动(想到使用jquery scrollbatr,但如何将它放在div2之外)。其次是两个divs之间的对等。

+0

我认为你自己的建议是要走的路....你所描述的问题有点不清楚......也许你可以添加一些示例代码或示例地址,我们可以看看? –

+0

请参阅以下链接:http://stackoverflow.com/questions/296020/how-can-i-lock-the-first-row-and-first-column-of-a-table-when-scrolling-possiblely http: //www.cubido.at/blogs/Lists/Posts/Post.aspx?ID=1259 – Brij

+0

Thanks..but的链接来解决不工作.. – Neo

回答

1

如果我明白你在找什么;我不久前做过类似的事情。

Html可能看起来像这样。

<table border="1" id="header"> 
    <tr> 
     <th></th> 
     <th></th> 
    </tr> 
</table> 
<div id="tableData"> 
    <table border="1" id="table"> 
     <td></td> 
     <td></td> 
    </table> 
</div> 

CSS

#tableData { 
    overflow: scroll; 
    overflow-x:hidden; 
    height: 190px; 
    border-bottom: 1px solid #B5B3B3; 
    width: 940px; 
} 

JavaScript才能确保头与您可能需要做出一些调整表数据

$("#tableData").height(190); 
$("#tableData").width(940); 
for(var i=1;i<8;i++){ 
    if($("#header th:nth-child("+i.toString()+")").width() >= $("#table td:nth-child("+i.toString()+")").width()) 
     $("#table td:nth-child("+i.toString()+")").width($("#header th:nth-child("+i.toString()+")").width()); 
    else 
     $("#header th:nth-child("+i.toString()+")").width($("#table td:nth-child("+i.toString()+")").width()); 
} 
$("#tableData").width($("#table").width()+20); 
if($("#table").height() <= $("#tableData").height()) 
    $("#tableData").height($("#table").height()); 

对齐,但是这是一个解决方案。我的变量需要覆盖每一列,在我的例子中它可以用于7列。

+0

@Neo请将此答案标记为已接受,如果它回答了您的问题,请提供有关未解决问题的反馈。谢谢 – Trevor

相关问题