Sortable Grid

Id First Name Last Name
10HelenBurke
1JonathanChapman
39StephanieFerguson
33HarryHarrison
45AnneHayes
15ThomasHayes
5AaronHolmes
21ScottNguyen
27ChrisWallace

Code

Inside MVCGridConfig.cs
MVCGridDefinitionTable.Add("SortableGrid", 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);
    })
    .WithSorting(true, "LastName")
    .WithRetrieveDataMethod((context) =>
    {
        var options = context.QueryOptions;
        var result = new QueryResult<Person>();
        using (var db = new SampleDatabaseEntities())
        {
            var query = db.People.Where(p => p.Employee);
            if (!String.IsNullOrWhiteSpace(options.SortColumnName))
            {
                switch (options.SortColumnName.ToLower())
                {
                    case "firstname":
                        query = query.OrderBy(p => p.FirstName, options.SortDirection);
                        break;
                    case "lastname":
                        query = query.OrderBy(p => p.LastName, options.SortDirection);
                        break;
                }
            }
            result.Items = query.ToList();
        }
        return result;
    })
);
View
@Html.MVCGrid("SortableGrid")