有谁知道如何在 ASP.NET MVC 4 中实现 serverGrouping 的服务器端部分——而不使用 Telerik 提供的 MVC 包装器?
我有 serverPaging、serverSorting 和 serverFiltering 工作,但不知道如何构造和发送分组数据。
这是我用于发送分页、排序和过滤数据的代码。
public class TicketGridController : ApiController
{
private SupplierDataContext db = new SupplierDataContext();
HttpRequest request = HttpContext.Current.Request;
// GET api/Tickets
public Response Get()
{
int skip = request["skip"] == null ? 0 : int.Parse(request["skip"]);
int take = request["take"] == null ? 10 : int.Parse(request["take"]);
string group = request["group"] == null ? "" : request["group"];
string status = request["filter[filters][0][value]"] == null ? "" : request["filter[filters][0][value]"];
string sort = request["sort[0][field]"] == null ? "" : request["sort[0][field]"];
bool sortUp = request["sort[0][dir]"] == null ? true : (request["sort[0][dir]"] == "asc" ? true : false);
var Tickets = db.Tickets.ToList();
if (!string.IsNullOrEmpty(status)) {
Tickets = Tickets.Where(t => t.Issues.Where(i => i.Status == 1).Count() > 0).ToList();
}
switch (sort) {
case "TicketID":
if (sortUp) Tickets = Tickets.OrderBy(t => t.TicketID).ToList();
else Tickets = Tickets.OrderByDescending(t => t.TicketID).ToList();
break;
case "TicketName":
if (sortUp) Tickets = Tickets.OrderBy(t => t.TicketName).ToList();
else Tickets = Tickets.OrderByDescending(t => t.TicketName).ToList();
break;
case "Status":
if (sortUp) Tickets = Tickets.OrderBy(t => t.Status).ToList();
else Tickets = Tickets.OrderByDescending(t => t.Status).ToList();
break;
default:
Tickets = Tickets.OrderByDescending(t => t.DateModified).ToList();
break;
}
// ---------------------------------
// ADD GROUPING SOMEHOW!?
// ---------------------------------
List<TicketDisplayObject> ts = new List<TicketDisplayObject>();
foreach (Ticket t in Tickets.Skip(skip).Take(take))
{
ts.Add(new TicketDisplayObject(t));
}
return new Response(ts.ToArray(), Tickets.Count());
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
有谁知道如何实现分组位?
提前致谢!