Tubular Grids with DotNet Library

Tubular provides a .NET library to easily create responses in WebApi library (or WCF) for your Tubular grids. This helpers and extension methods provide sorting, filtering and pagination using System.Linq.Dynamic.

You can install from Nuget:

PM> Install-Package Tubular.ServerSide

You first need to setup your ApiController. All the request made by Tubular Grid are using HTTP POST method, in order to send a GridDataRequest model. This model provides an extension method to generate a payload using any IQueryable data source like an Entity Framework query.

The internal helper will deliver a GridDataResponse model. This model is the expected payload for Tubular Grid. You need to use both classes in order to use Tubular Grid properly, if you only return a simple IQueryable or List<T> the Tubular component won't be able to populate.

Heads up! You can also use this helper with EmbedIO web server.
[RoutePrefix("api/users")] public class UsersController : ApiController { [HttpPost, Route("paged")] public IHttpActionResult GridData([FromBody] GridDataRequest request) { using (var context = new SampleDbContext(false)) { return Ok(request.CreateGridDataResponse(context.SystemUsers)); } } }

Since you pass a IQueryable as parameter, you can filter or apply any security level control before to call the CreateGridDataResponse. If you require to apply any transformation that you can't perform in, for example, Entity Framework like convert date to a specific string format you can use a final output process (ProcessResponseSubset function argument).

[RoutePrefix("api/users")] public class UsersController : ApiController { private static IQueryable FormatOutput(IQueryable q) { var list = new List(); foreach (var i in q) { var item = i as SystemUser; item.Password = "*****"; list.Add(item); } return list.AsQueryable(); } [HttpPost, Route("paged")] public IHttpActionResult GridData([FromBody] GridDataRequest request) { using (var context = new SampleDbContext(false)) { return Ok(request.CreateGridDataResponse(context.SystemUsers, FormatOutput)); } } }

From the previous sample, the second argument in CreateGridDataResponse function is a static function where the input parameter is anonymous IQueryable and returns another anonymous IQueryable. You need to cast the inner list in order to materialize from Entity Framework IQueryable. Using a second IQueryable to return is recommended instead to modify the incoming IQueryable.

It's important to use the ProcessResponseSubset parameter to perform any transformation to improve performance because if you materialize your Entity Framework IQueryable before to pass it to Tubular, all the paging and filtering will apply to the complete dataset.