2013-06-21 49 views
1

我想解決我的webgrids的標題在上面。所以當你滾動時,標題保持原位。MVC4 WebGrid頭固定在頂部

我試過CSS。和Javascript,沒有成功。

而且大多數解決方案都需要爲每列已知寬度。它的一個的WebGrid,有每列沒有固定的寬度..

有誰知道正確的方式做到這一點?

潤通/所有的解決方案,標題甚至不與錶行..

<script type="text/javascript"> 
     $(document).ready(function() { 
      $("#GridHeader").html("<table>" + $('#gridContent table thead').html() + "</table>"); 
      $("#GridHeader table tr:first").append("<th style='width:12px;' ></th>"); 
      $("#GridBody").html("<table>" + $('#gridContent table tbody').html() + "</table>"); 
      $("#GridFooter").html("<table>" + $('#gridContent table tfoot').html() + "</table>"); 
      $("#gridContent").hide(); 
     }); 

<style type="text/css"> 
.colWidth { width: 200px; } 
#GridBody{width: 100% ;height:200px; overflow: auto; } 
#GridHeader table {width: 100%; margin-top: 0px; padding:0px; border-collapse:collapse; } 
#GridFooter {width: 100% ; } 
#GridHeader table th { width: 10%; border: 2px solid black;} 
.title td, .title th { width: 10%; border: 2px solid black;} 
#GridBody td { width: 10%; border: 2px solid black;} 
</style> 

<div id="Outer" > 
<div id="GridHeader" class="title"></div> 
<div id="GridBody"></div> 
<div id="GridFooter"></div> 
</div> 
+0

嘗試使用jquery clone方法複製標題 – Andrei

+0

爲什麼我要複製標題? @AndreiMikhalevich – Mcloving

+0

嘗試'位置:固定;' –

回答

0

嘗試克隆滿格與jQuery,然後刪除TBODY克隆元素並將其餘部分修復在頁面頂部。這是我該怎麼做

+0

頁面上有多個表格.. – Mcloving