EasyUI DataGrid 分页实现示例
使用easyui可以很方便的开发web程序,这儿仅展示一个后台使用mvc来实现分页的示例,截图如下

示例代码如下
1. 创建模型类,代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace EasyuiDemo.Models
{
public class Student
{
public int ID { get; set; } public string Name { get; set; } public int Age { get; set; }
}
}
2. 因为easyui加载数据的格式有要求,所以创建一个模型包装类以方便序列化为json,代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace EasyuiDemo.Models
{
public class PageModel<T>
{
public int total { get; set; } public List<T> rows { get; set; }
}
}
3. 在控制器中创建一个静态的模型集合以作为数据源,并提供对应的处理分页的动作,代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EasyuiDemo.Models;
using Newtonsoft.Json; namespace EasyuiDemo.Controllers
{
public class HomeController : Controller
{
private static List<Student> list; static HomeController()
{
list = new List<Student>();
list.Add(new Student() { ID = , Name = "aa", Age = });
list.Add(new Student() { ID = , Name = "bb", Age = });
list.Add(new Student() { ID = , Name = "cc", Age = });
list.Add(new Student() { ID = , Name = "dd", Age = });
list.Add(new Student() { ID = , Name = "ee", Age = });
list.Add(new Student() { ID = , Name = "ff", Age = });
list.Add(new Student() { ID = , Name = "gg", Age = });
list.Add(new Student() { ID = , Name = "hh", Age = });
list.Add(new Student() { ID = , Name = "ii", Age = });
list.Add(new Student() { ID = , Name = "jj", Age = });
} // GET: Home
public ActionResult Index()
{
return View();
} public string Page()
{
int page = ;
int rows = ;
if(Request.Params["page"] != null)
{
page = Convert.ToInt32(Request.Params["page"]);
}
if (Request.Params["rows"] != null)
{
rows = Convert.ToInt32(Request.Params["rows"]);
}
PageModel<Student> pdata = new PageModel<Student>();
pdata.total = list.Count;
pdata.rows = list.GetRange(rows * (page - ), rows);
return JsonConvert.SerializeObject(pdata);
}
}
}
4. 视图页面代码如下
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link rel="stylesheet" href="~/Content/themes/default/easyui.css"/>
<script src="~/scripts/jquery-1.11.3.js"></script>
<script src="~/scripts/jquery.easyui-1.4.5.js"></script>
<script>
$(function () {
$("#dg").datagrid({
url: "/home/page",
columns: [[
{ field: 'ID', title: 'ID', width: 100 },
{ field: 'Name', title: 'Name', width: 100 },
{ field: 'Age', title: 'Age', width: 100 }
]],
pageSize: 5,
pageList: [5, 10],
pagination: true
})
})
</script>
</head>
<body>
<div id="dg">
</div>
</body>
</html>
datagrid设定pageSize时必须设定pageList,且pageSize的值要在pageList中,否则就是用默认的10.
如上就完成了datagrid的分页是用。
EasyUI DataGrid 分页实现示例的更多相关文章
- EasyUI DataGrid分页数据绑定
记录东西感觉很痛苦,总结东西很痛苦,麻烦,不过为了下次的方便和知识的牢固以后要坚持总结. EasyUI DataGrid分页数据绑定 在解决方案中新建两个文件FormMain.aspx(html也可以 ...
- EasyUI datagrid 分页Json字符串格式
//EasyUI datagrid 分页Json字符串格式 //{"total":xx,"rows":[{...},{...}]} total:总数 rows: ...
- asp.net mvc easyui datagrid分页
提到 asp.net mvc 中的分页,很多是在用aspnetpager,和easyui datagrid结合的分页却不多,本文介绍的是利用easyui 中默认的分页控件,实现asp.net mvc分 ...
- easyUI datagrid 分页参数page和rows
Struts2获取easyUI datagrid 分页参数page和rows 用pageHelper分页时,只要是能够获取前台传来的两个参数page和rows基本就完成了很大一部分. 获取方法:定义两 ...
- EasyUI Datagrid 分页显示(客户端)
转自:https://blog.csdn.net/metal1/article/details/17536185 EasyUI Datagrid 分页显示(客户端) By ZYZ 在使用JQuery ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(8)-MVC与EasyUI DataGrid 分页
系列目录 前言 为了符合后面更新后的重构系统,文章于2016-11-1日重写 EasyUI Datagrid在加载的时候会提交一些分页的信息到后台,我们需要根据这些信息来进行数据分页再次返回到前台 实 ...
- easyui datagrid 分页略解
easyui datagrid 本身自带了分页功能. 但是这个需要你自己控制. 在后台可以得到两个datagrid的参数,rows 和page.其中rows是每页要显示的个数,page是第几页.单纯的 ...
- jquery easyui datagrid 分页详解
由于项目原因,用了jquery easyui 感觉界面不错,皮肤样式少点,可是官网最近打不开了,资料比较少,给的demo没有想要的效果,今天在用datagrid 做分页显示的时候,折腾了半天,网上的资 ...
- easyui datagrid分页
datagrid分页设置 pagination="true" 貌似是不行的! 只是显示分页工具栏 没有达到分页效果 前端 $(function (){ var p = $('#d ...
随机推荐
- 用unity4.3发布WINDOWS STORE APP应用的方法
http://www.cnblogs.com/suxsho/ 原创,转载请声明 ============================================================ ...
- Python2.7.12开发环境构建(自动补全)
一.安装readline-devel包 Python的编译安装依赖于这个包 yum -y install readline-devel 二.安装Python2.7.12 Python官方网站(到此处下 ...
- 零基础如何自学MySQL数据库?
作者:姜健链接:https://www.zhihu.com/question/34840297/answer/67536521来源:知乎著作权归作者所有,转载请联系作者获得授权. 本人是个活生生的例子 ...
- Myeclipse添加外部Tomcat出现启动故障的问题解决
故障: 1.java.lang.IllegalStateException: No output folder 分析:work文件夹无写权限 解决:找到tomcat的安装文件夹,右键点击work文件夹 ...
- Zookeeper 的学习与运用
引子 云计算越来越流行的今天,单一机器处理能力已经不能满足我们的需求,不得不采用大量的服务集群.服务集群对外提供服务的过程中,有很多的配置需要随时更新,服务间需要协调工作,这些信息如何推送到各个节点? ...
- Python + Selenium 实现登录Office 365
最近捡起之前用的Python + Selenium实现工作中需要的登录Office 365功能.(吐槽:国内网络真是卡,登录Office 365实属不易.另外Selenium这样的网站都要墙,无法理解 ...
- (转) Playing FPS games with deep reinforcement learning
Playing FPS games with deep reinforcement learning 博文转自:https://blog.acolyer.org/2016/11/23/playing- ...
- CentOS 7下源码安装MySQL 5.6
本文转载,并非原创. 目录 准备工作 运行环境 确认你的安装版本 下载MySQL 安装MySQL 准备安装环境 编译和安装 配置MySQL 单实例配置 单实例配置方法 添加防火墙 启动MySQL 重启 ...
- 视图(View) – ASP.NET MVC 4 系列
精心编写的整洁代码是开发一个可维护 Web 应用程序的基础.但用户在浏览器中访问时,这些工作他们是看不见的.用户对应用程序的第一印象,以及与应用程序的整个交互过程都是从视图开始的. ...
- SQL系统数据库简介(mssqlsystemresource)
mssqlsystemresource