Render button, checkbox etc in the grid cell

To render custom html markup in the grid cell you should use RenderValueAs method. Also you need to disable default encoding and satinizing cell values, using Encoded and Sanitized method.

Button

columns.Add()
        .Encoded(false)
        .Sanitized(false)
        .SetWidth(30)
        .RenderValueAs(o => @<button type="submit">Submit</button>);

Checkbox

columns.Add()
        .Encoded(false)
        .Sanitized(false)
        .SetWidth(30)
        .RenderValueAs(o => Html.CheckBox("checked", false));

Custom layout

You can render any custom layout, using razor @helper:

@helper CustomRenderingOfColumn(Order order)
{
    if (order.Customer.IsVip)
    {
    <text>Yes</text>
    }
    else
    {
    <text>No</text>
    }
}

@Html.Grid(Model)..Columns(columns =>
{
        columns.Add(o => o.Customer.IsVip)
                .Titled("Vip customer")
                .SetWidth(150)
                .RenderValueAs(o => CustomRenderingOfColumn(o));
})

Last edited Jul 17, 2013 at 3:09 AM by Bukharin, version 1