I am using the following method to get data for my jqgrid's subgrid and its working completely fine.
Note that this method is used to implement server-side sorting and paging.
Now the query I have is as you can see in the line
List<SomeEntity> myList = _service.GetSomeData(id);
here a database call is made and all records are fetched.
So I was just not very sure, So I just wanted to know if this is in with the best practice to implement serverside paging and
public JsonResult GetData(string folderId, string sidx, string sord, int page, int rows) {
int id = int.Parse(folderId);
List < SomeEntity > myList = _service.GetSomeData(id);
const int pageSize = 5;
// total
double totalPages = Math.Ceiling((double) myList.Count() / pageSize);
// sort
if (sord == "asc") {
myList = myList.OrderBy(m = > m.Name).ToList();
}
else {
myList = myList.OrderByDescending(m = > m.Name).ToList();
}
// paging
myList = myList.Skip((page - 1) * pageSize).Take(pageSize).ToList();
var jsonData = new {
total = totalPages, records = domainList.Count, page,
rows = myList
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}