I use the following method to get data for my jggrid subgrid and its operation is completely normal.
Note that this method is used to implement server-side sorting and swapping.
Now I have a request, as you can see in the line
List<SomeEntity> myList = _service.GetSomeData(id); a database call is made here and all records are retrieved.
So I was just not very sure, so I just wanted to know if there is best practice in this practice for implementing server 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;
double totalPages = Math.Ceiling((double) myList.Count() / pageSize);
if (sord == "asc") {
myList = myList.OrderBy(m = > m.Name).ToList();
}
else {
myList = myList.OrderByDescending(m = > m.Name).ToList();
}
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);
}β
source
share