private JsonResult FilterDataSource(int total, ParameterGridDefault parameters) { var orderGrid = true; //var iqueryable = _datasource; //as IEnumerable; //IQueryable; var num3 = total; parameters.total = total; var totalPageCount = (int)Math.Ceiling((float)num3 / (float)parameters.rows); IQueryable iqueryable = _datasource.AsQueryable(); //(_datasource as IQueryable); //.Skip(parameters.rows * (parameters.page - 1)) //.Take(parameters.rows); if (!string.IsNullOrEmpty(parameters.sidx)) { var text5 = string.Empty; if (parameters.sidx != null && parameters.sidx == " ") { parameters.sidx = string.Empty; } if (!string.IsNullOrEmpty(parameters.sidx)) { //if (!text5.EndsWith(",")) //{ // // text5 += ","; //} text5 = text5 + parameters.sidx + " " + parameters.sord; } iqueryable = iqueryable.OrderBy(text5, new object[0]); } var iqueryablepaging = iqueryable.Skip(parameters.rows * (parameters.page - 1)).Take(parameters.rows); var dataTable = iqueryablepaging.ToDataTable <T>(); var response2 = new JsonResponse(parameters.page, totalPageCount, num3, parameters.rows, dataTable.Rows.Count, null); var res = Util.ConvertToJson(response2, dataTable); return(res); }
public JsonResult DataBind(IEnumerable <T> datasource, int total) { _datasource = datasource; var request = HttpContext.Current.Request; var parameters = new ParameterGridDefault(); if (request.RequestType == "POST") { parameters.page = Convert.ToInt32(request.Form["page"]); parameters.rows = Convert.ToInt32(request.Form["rows"]); parameters.sidx = request.Form["sidx"]; parameters.sord = request.Form["sord"]; } else { parameters.page = Convert.ToInt32(request.QueryString["page"]); parameters.rows = Convert.ToInt32(request.QueryString["rows"]); parameters.sidx = request.QueryString["sidx"]; parameters.sord = request.QueryString["sord"]; } return(this.FilterDataSource(total, parameters)); }