调整表头大小以匹配ASP.net GridView生成的表体
Resize table header to match the table body generated by ASP.net GridView
我有以下小提琴:http://jsfiddle.net/byB9d/3282/
脚本:
function removeClassName (elem, className) {
elem.className = elem.className.replace(className, "").trim();
}
function addCSSClass (elem, className) {
removeClassName (elem, className);
elem.className = (elem.className + " " + className).trim();
}
String.prototype.trim = function() {
return this.replace( /^'s+|'s+$/, "" );
}
function stripedTable() {
if (document.getElementById && document.getElementsByTagName) {
var allTables = document.getElementsByTagName('table');
if (!allTables) { return; }
for (var i = 0; i < allTables.length; i++) {
if (allTables[i].className.match(/['w's ]*scrollTable['w's ]*/)) {
var trs = allTables[i].getElementsByTagName("tr");
for (var j = 0; j < trs.length; j++) {
removeClassName(trs[j], 'alternateRow');
addCSSClass(trs[j], 'normalRow');
}
for (var k = 0; k < trs.length; k += 2) {
removeClassName(trs[k], 'normalRow');
addCSSClass(trs[k], 'alternateRow');
}
}
}
}
}
window.onload = function() { stripedTable(); }
我如何才能确保头部与身体匹配。
我建议更改您的表结构。您可以制作一个固定的表头,而无需将其拆分为两个表。
HTML
<div class="container">
<div class="container-inner">
<table>
<thead>
<tr>
<th><div class="th-inner">First</div></th>
<th><div class="th-inner">Second</div></th>
<th><div class="th-inner">Third</div></th>
</tr>
</thead>
<tbody>
<!-- Your table content here -->
</tbody>
</table>
</div>
</div>
CSS
.container {
position: relative; /* could be absolute or relative */
padding-top: 30px; /* height of header */
height: 200px; /* the height your table should be */
}
.container-inner {
overflow-x: hidden;
overflow-y: auto;
height: 100%;
}
.th-inner {
position: absolute;
top: 0;
line-height: 30px; /* height of header */
}
JSFiddle演示
其他固定表头的来源、更多信息和示例可以在这里找到。
您的头中有7项,td中只有6项,因此,它永远不会匹配。
去掉所有的CSS,标题与表的其余部分对齐。这个问题肯定在CSS中。
问题在CSS中。只需将display: block
从html>body thead.fixedHeader tr
和html>body tbody.scrollContent
中移除即可。
这是小提琴。
相关文章:
- 选择不在GridView-ASP.NET中激发
- 使用Jquery查找asp.net GridView中的所有复选框
- 从asp.net中的ClientSide(Javascript)刷新GridView
- 如何使用asp.net将gridview的行号作为命令参数传递
- 如何在页面回发后保持Asp-Net GridView数据(来自SignalR)
- 调整表头大小以匹配ASP.net GridView生成的表体
- 使用javascript将JSON对象绑定到asp.net gridview控件
- 如何在右键单击时获取 ASP.NET GridView在jQuery中的单元格ID
- 从 GridView 执行 Javascript 函数 ItemTemplate“按钮单击”Web 窗体 ASP.NET
- 如何将 JavaScript 添加到 Gridview 的下拉列表(模板归档 ASP.NET
- 在 asp.net 的 GridView 中使用 ColorBox
- 使用 jQuery mobile 和 ASP.NET Gridview 的响应式表
- GridView asp .net 中的日期范围验证
- 如何在asp.net中的javascript窗口.open中从gridview调用id
- 在asp.net中,带有引导程序的对话框模式中的Gridview onclick-in会将值返回到模式父页Web表单
- 在gridview中javascript确认后未触发Onclick asp.net事件
- 将GridView id传递给asp.net中的JavaScript函数
- ASP.NET GridView ItemTemplate LinkButton支持RowCommand AFTER J
- 在asp.net web应用程序中使用jQuery表替换GridView
- GridView RowDataBound事件降低了应用程序ASP.NET C#的速度