4

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

for all header element....................

$("#gridContent").find('table thead tr a')

and then apply style any this u want see

.addClass() .append()

for individual header.....................

actually this is applying style of rowcell to the headercell

var headerCells = $("#gridContent table tr th");

var firstRowCells = $("#gridContent table tr td");

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

also see MVC3 WebGrid Formatting or Styling Column Headers

How to add Html inside ASP.NET MVC 3 WebGrid Column Name (Header)

MVC3 WebGrid Formatting or Styling Column Headers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.