我正在使用新的 MVC3 WebGrid。到目前为止一切顺利,只是在列标题的样式/格式方面存在问题。我得到的最好的解决方法是将 WebGrid 第一行中的相同 css 类应用于表头。
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"));
});
这个例子显然缺乏检查以确保有行或确实有指定的元素 id,但它将第一行的 css 类应用到标题行,这意味着您可以彼此独立地设置样式。
td.my-column-style { width:100px }
th.my-column-style { text-align:right;}
是否有一种内置的方式来设置列标题元素的样式(不仅仅是使用 headerStyle 属性)?