Custom Data Formatting

StartDate column is formatted to ShortDateTime and View is a link containing the ID.

Id First Name Last Name Start Date
370PatrickAdams1/3/2015View
493KarenAdams1/25/2014View
570NancyAdams6/14/2014View
599EricAdams12/10/2013View
635ChristineAdams10/13/2011View
663BonnieAdams10/27/2011View
778RonaldAdams8/19/2011View
820SeanAdams4/2/2014View
897JudithAdams2/25/2013View
857MichaelAlexander6/23/2014View
Showing 1 to 10 of 1000 entries

Code

Inside MVCGridConfig.cs
MVCGridDefinitionTable.Add("FormattingGrid", new MVCGridBuilder<Person>(colDefauls)
    .WithAuthorizationType(AuthorizationType.AllowAnonymous)
    .AddColumns(cols =>
    {
        cols.Add("Id").WithSorting(false)
            .WithValueExpression(p => p.Id.ToString());
        cols.Add("FirstName").WithHeaderText("First Name")
            .WithValueExpression(p => p.FirstName);
        cols.Add("LastName").WithHeaderText("Last Name")
            .WithValueExpression(p => p.LastName);
        cols.Add("StartDate").WithHeaderText("Start Date")
            .WithValueExpression(p => p.StartDate.HasValue ? p.StartDate.Value.ToShortDateString() : "");
        cols.Add("ViewLink").WithSorting(false)
            .WithHeaderText("")
            .WithHtmlEncoding(false)
            .WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
            .WithValueTemplate("<a href='{Value}'>View</a>");
    })
    .WithSorting(true, "LastName")
    .WithPaging(true, 10)
    .WithRetrieveDataMethod((context) =>
    {
        var options = context.QueryOptions;
        int totalRecords;
        var repo = DependencyResolver.Current.GetService<IPersonRepository>();
        var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
            options.SortColumnName, options.SortDirection == SortDirection.Dsc);
        return new QueryResult<Person>()
        {
            Items = items,
            TotalRecords = totalRecords
        };
    })
);
View
@Html.MVCGrid("FormattingGrid")