MVC3 WebGrid格式化或样式列标题

sam*_*tin 12 coding-style header webgrid asp.net-mvc-3

我正在使用新的MVC3 WebGrid.到目前为止一直很好,只是有问题样式/格式化列标题.我得到的最好的解决方法是将同一个css类从WebGrid的第一行应用到表头.

var headerCells = $("#grid tr:eq(0) th");
var firstRowCells = $("#grid tr:eq(1) td");

$.each(firstRowCells, function (index, value) {
    $(headerCells[index]).addClass($(firstRowCells[index]).attr("class"));
});
Run Code Online (Sandbox Code Playgroud)

此示例显然缺少检查以确保存在行或确实指定的元素id,但它将第一行中的css类应用于标题行,这意味着您可以相互独立地设置样式.

td.my-column-style { width:100px }
th.my-column-style { text-align:right;}
Run Code Online (Sandbox Code Playgroud)

是否有内置的样式列标题元素的方式(不只是使用headerStyle属性)?

Dan*_*l P 5

不,到目前为止,还没有内置的方法可以单独设置标题单元格的样式,仅通过headerStyle属性设置标题行。

我认为您的解决方法足够好。

  • 谢谢,这似乎很有限,不是吗? (2认同)