It's not an HTML table, exactly, but I use jqGrid along with Craig Stuntz's helper functions to "export" any IQueryable<T>
as JSON. The helper function ToJqGridData
sends JSON in exactly the format required by jqGrid, so your code is nice and neat:
MyObjectRepository rep = new MyObjectRepository();
var myObjects = from o in rep.SelectAll()
select new
{
Prop1 = o.Prop1,
Prop2 = o.Prop2
...
}
return Json(apps.ToJqGridData(page, rows, sidx, null, null), JsonRequestBehavior.AllowGet);
Be aware you'll also need to update the global settings for your jqGrids to make them compatible with the naming conventions used by ToJqGridData
(I just include this script in my master page):
$(document).ready(function() {
GridDemo.SiteMaster.setDefaults();
});
var GridDemo = {
Home: {
GridDemo: {}
},
SiteMaster: {
setDefaults: function() {
$.jgrid.defaults = $.extend($.jgrid.defaults, {
datatype: 'json',
height: 'auto',
imgpath: '/Scripts/jqGrid/themes/lightness/images',
jsonReader: {
root: "Rows",
page: "Page",
total: "Total",
records: "Records",
repeatitems: false,
userdata: "UserData",
id: "Id"
},
loadui: "block",
mtype: 'GET',
multiboxonly: true,
rowNum: 20,
rowList: [10, 20, 50],
viewrecords: true
});
}
}
};