EasyUI Forum
May 17, 2024, 06:46:54 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Paging not work in easyui datagrid  (Read 10435 times)
Vilisag
Newbie
*
Posts: 16


View Profile
« on: December 17, 2014, 09:16:06 AM »

Hi all,
  I use easyui datagrid in my project, I load data successfully but paging not work.
Please help me, thank for help!!
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: December 18, 2014, 01:24:32 AM »

The json data returned from server should have 'total' and 'rows' properties. It looks like this:
Code:
{"total":xxx,"rows":[...]}
Logged
Vilisag
Newbie
*
Posts: 16


View Profile
« Reply #2 on: December 18, 2014, 06:37:32 AM »

It not work!!!
Server -side code:
Code:
public JsonResult DanhSachTinh(int page = 1, int rows = 10)
        {
            var tinh = db.Tinhs.ToList() as IEnumerable<Tinh>;
            var pageIndex = Convert.ToInt32(page) - 1;
            var pageSize = rows;
            var totalRecords = tinh.Count();
            var totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
            tinh = tinh.Skip(pageIndex * pageSize).Take(pageSize);
            var jsonData = new
            {
                total = totalPages,
                rows = tinh.Select(e => new
                {
                    tinhId = e.tinhId,
                    maTinh = e.maTinh,
                    tenTinh = e.tenTinh
                }).ToArray()
            };
            //return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(db.NhanViens.ToList());
            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }
« Last Edit: December 18, 2014, 09:39:18 AM by Vilisag » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: December 18, 2014, 07:00:16 AM »

Please use the browser's network tool to see what returned from your server. The datagrid pagination tutorial is available from http://www.jeasyui.com/tutorial/datagrid/datagrid2.php
Logged
Vilisag
Newbie
*
Posts: 16


View Profile
« Reply #4 on: December 18, 2014, 09:57:43 AM »

Thanks stworthy, i had seen issue.
My code is redundant:
 
Code:
var totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

And code true:
Code:
public JsonResult DanhSachTinh(int page = 1, int rows = 10)
        {
            var tinh = db.Tinhs.ToList() as IEnumerable<Tinh>;
            var pageIndex = page;
            var pageSize = rows;
            var totalRecords = tinh.Count();
            tinh = tinh.Skip(pageIndex * pageSize).Take(pageSize);
            var jsonData = new
            {
                total = totalRecords,
                rows = tinh.Select(e => new
                {
                    tinhId = e.tinhId,
                    maTinh = e.maTinh,
                    tenTinh = e.tenTinh
                }).ToArray()
            };
            //return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(db.NhanViens.ToList());
            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!