Adding custom html to Header in WebGrid

harry mohammed picture harry mohammed · Jun 7, 2011 · Viewed 10.7k times · Source

I'm trying to add a custom header for an MVC3 WebGrid.

The header property only allows for string, and any HTML is escaped.

My current grid razor view is as follows:

var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5);
            grid.Pager(WebGridPagerModes.NextPrevious);

            @grid.GetHtml(tableStyle: "data_table-sorter",
                alternatingRowStyle: "odd",
                columns: grid.Columns(
                grid.Column(header:"Select<span class=\"fi fi_gear\"></span>\"" , style: "table-select-col has-menu", canSort: false, format: @<input type="checkbox" value="@item.Id" />),
                grid.Column("Name", "Briefing Book Name", canSort: true, style: "dj_sortable-table-column"),
                grid.Column("Format", "Format", canSort: true, style: "dj_sortable-table-column") 
));

How can I do this?

Answer

Mike Brind picture Mike Brind · Jun 8, 2011

If you want to style individual headers in the current version of the WebGrid, you will have to use client-side code to do that.