Rewriting the MvcContrib Grid

This is part 1 of a series on the new MvcContrib grid component.

Over the next couple of weeks I'm hoping to write a few posts on the upgrades I'm doing to the MvcContrib grid component. These are the features that I'm planning on adding:

A Fluent Interface

Like the HTML-helpers built into the ASP.NET MVC framework, the mvccontrib grid suffers from 'overload hell'. Switching to a fluent interface should provide a cleaner and more discoverable API.

Discouraging logic in Views

One side effect of the fluent interface is that it will no longer be possible to use the grid's section overrides. However, I consider this to be a good thing. Embedding custom sections makes it all to easy to get stuck in 'tag soup'. To make up for this, the new grid will support rendering partials for custom sections.

Reusable Grid Models

The new grid will support reusable grid definitions. That is, you will be able to define a grid in a external class and then reference this from your views. One benefit of this approach is that it means the grid will finally be accessible to VB users. The current grid is C#-only due to its use of lambda-statements for defining columns.

Customisable Grid Rendering

The existing grid only supports rendering in an HTML table. This means that if you wanted to render a grid in a different format (for example, as an OpenXML Spreadsheet) it meant you needed to inherit from the Grid class, override several methods and then create a new helper. The new grid will allow a custom GridRenderer class to be provided in the grid definition. Rendering as an HTML table will still be the default behaviour.

Separate Pagination Component

The current grid has built in support for paging. With the new grid, this will be moved into a separate component.


Time permitting, the new grid will have support for sorting.

In my next post I'll focus on the grid's Fluent Interface.