views:

38

answers:

1

I have a partial view that uses a Telerik MVC Grid, and it has column binding code as follows (very partial view):

.Columns(column =>
{
    column.Bound(model => model.PlannedFinishDate).Title("Planned Date").Format("{0:dd/MM/yyyy}").Width(83);
    column.Bound(model => model.Province).Width(70);
    if (Roles.IsUserInRole("Controller") == true)
    {
        column.Bound(model => model.InstallerName).Width(85);
        column.Bound(model => model.InstallerAccepted).Title("Accepted").Width(45);
        column.Bound(model => model.KitShippedDescription).Width(70);
    }
// etc. etc.

Now I need to write a controller action to export the same data as rendered in the grid to Excel, and I need the same role based column inclusion/exclusion. I don't want to duplicate the role checking logic, so I'm looking for a way to generate the data used here for column binding in the controller, pass it with the ViewData, and use it in the view to dynamically bind the columns.

A: 

Perhaps this example would help. There is a disclaimer though - this is still in beta and the final API will change from

.Columns((IEnumerable<GridColumnSettings<T>>)ViewData["Columns"])

to

.Columns(columns => columns.LoadSettings((IEnumerable<GridColumnSettings<T>>)ViewData["Columns"]))
korchev
I can't find the GridColumnSettings type anywhere.
ProfK
It looks like *GridColumnSettings* is new to Q2, still in beta, so I won't be allowed to use it in a production app.
ProfK
It will be official shortly.
korchev
That's great @korchev. It's a great product and I look foward to beign able to use Q2.
ProfK