Skip to content

Instantly share code, notes, and snippets.

@tawman
Created February 19, 2012 02:18
Show Gist options
  • Save tawman/1861658 to your computer and use it in GitHub Desktop.
Save tawman/1861658 to your computer and use it in GitHub Desktop.
PetaPocoPage Helper to format the JSON page response to DataTables
using System.Globalization;
using System.Linq;
using PetaPoco;
using PetaPocoPage.Models;
namespace PetaPocoPage.Helpers
{
public class DataTablesFormat
{
public static object PageResponse(DataTablesPageRequest pageRequest, Page<Customer> report)
{
return new
{
sEcho = pageRequest.Echo,
iTotalRecords = report.TotalItems,
iTotalDisplayRecords = report.TotalItems,
sColumns = pageRequest.ColumnNames,
aaData = (from i in report.Items
select new[]
{
i.Id.ToString(CultureInfo.InvariantCulture),
i.Last,
i.First,
i.Street,
i.City,
i.State,
i.Zip,
i.Phone,
i.Email
}).ToList()
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment