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 ...
随机推荐
- Sqlserver 函数(例子)
--SQL SERVER 2008 函数大全/*author:TracyLeecsdncount:Travylee*/ /*一.字符串函数:1.ascii(字符串表达式) 返回字符串中最右侧字符的 ...
- cloudera manager安装spark后使用spark shell编写基于scala的world count
val file = sc.textFile("hdfs://zhcloudil-lcnode04:8020/user/cloudil/wc_spark.txt") val cou ...
- 编程:递归编程解决汉诺塔问题(用java实现)
Answer: //Li Cuiyun,October 14,2016. //用递归方法编程解决汉诺塔问题 package tutorial_3_5; import java.util.*; publ ...
- Struts2中通过超链接传参数要注意的问题
写到分页的功能,在传递页码pageNo的时候遇到了参数接收不正确的问题,我本来在action中是定义了一个pageNo字符串参数和一个Page类参数,Page是一个封装了页面要显示的数据集合和页面信息 ...
- SQL系统数据库简介(mssqlsystemresource)
mssqlsystemresource
- CentOS 7 ssh脚本 求两个数值的“和”,“乘积”,”商“
1:在目录下创建一个 sh文件 touch 1.sh 2:进入sh文件书写sh脚本 #!/bin/bash read -p "请输入第一个数值" A read -p " ...
- Elasticsearch【JAVA REST Client】客户端操作
ES系统作为集群,环境搭建非常方便简单. 现在在我们的应用中,如何对这个集群进行操作呢? 我们利用ES系统,通常都是下面的架构: 在这里,客户端的请求通过LB进行负载均衡,因为操作任何一个ES的实例, ...
- 如何区分Babel中的stage-0,stage-1,stage-2以及stage-3(二)
上一篇文章我们介绍了法力无边的stage-0 和 包罗万象的stage-1, 现在我们来介绍下 stage-2 和 stage-3 深藏不露的stage-2 为什么说 stage-2深藏不露呢,因为它 ...
- 学会使用notepad++
官网地址:https://notepad-plus-plus.org/ 字体尺寸更改:ctrl+鼠标滚轮 主题:设置-语言格式设置,推荐Obsidian或者Zenburn主题,推荐Consolas 1 ...
- Log4net按照不同级别写入多个日志文件
[assembly: log4net.Config.XmlConfigurator(Watch = true)]//注入 在一个Web应用项目中,我使用了Fluent NHibernate作为数据访问 ...