asp.net-mvc - mvc3 WebGrid 中的两行标题

标签 asp.net-mvc asp.net-mvc-3 webgrid

有没有办法在 WebGrid 中拥有两行标题?

我寻找一种方法来对标题进行自定义渲染,或者寻找一种仅渲染表格主体(没有表格标签)的方法,但我找不到任何东西。

我想创建一个看起来像这样的网络网格:

-------------------------------------------
|grouped cols                |grouped cols|
-------------------------------------------
|col1 |  col2 | col3 | col4  | col5 |col6 |
-------------------------------------------
-------------------------------------------
|d1   |  d2   | d3   | d4    | d5   |d6   |
-------------------------------------------
|d1   |  d2   | d3   | d4    | d5   |d6   |
-------------------------------------------
|d1   |  d2   | d3   | d4    | d5   |d6   |
-------------------------------------------

请记住,我是 mvc3 的新手(所以我可能会错过明显的解决方案)。

最佳答案

服务器端解决方案:

@(new HtmlString(grid.GetHtml(Your grid definition).ToHtmlString()
    .Replace("<thead>",""<thead><tr class='webgrid-header'><th scope='col' colspan='4'>cols 1 to 4</th><th scope='col' colspan='2'>cols 5 and 6</th></tr>")))

客户端(假设 View 中只有一个 webgrid,您可以使用一些 jquery):

@Scripts.Render("~/bundles/jquery")
<script>
    $(function () {
        var th = $("<tr class='webgrid-header'><th scope='col' colspan='4'>col 1 to 4</th><th scope='col' colspan='2'>col 5 and 6</th></tr>")
        $("thead").prepend(th);
    });
</script>

关于asp.net-mvc - mvc3 WebGrid 中的两行标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17398688/

相关文章:

asp.net-mvc - MVC 3 WebGrid Column 按字母顺序排序,而不是根据表结构

asp.net-mvc-3 - 为什么 WebGrid 在格式化时使用动态?

asp.net-mvc - 使用 Recaptcha 对 Action 进行单元测试

asp.net-mvc-3 - 当两个网格位于同一页面上时进行排序

javascript - jqGrid 使用 Backbone 进行分页

c# - 使用 Enterprise Library 5.0 数据访问问题

asp.net-mvc - 如何设置 webgrid 行样式内联

jquery - 如何记住 Kendo Grid 中第二次请求的过滤器值?

c# - 为什么不调用 GetVaryByCustomString

asp.net - 如何在 ASP.NET MVC 中配置 3 级 URL?