(转)EasyUI 分页总结

摘要:
最近,我使用了easyui的分页和搜索栏功能。由于使用不熟练,在使用过程中出现了一些问题。这里有一个总结供大家学习。1.首先,使用EasyUI的DataGrid分页,然后加载其js类库:<linkrel=“stylesheet”type=“text/css”href=“http://www.jeasyui.com/easyui/themes/default/easyui.css“&gt&

最近用到了easyui的分页和搜索栏功能,使用过程中由于运用不熟练导致其间也出现过一些问题,下面做个小结,供大家共同学习。
1.首先使用EasyUI 的DataGrid分页,得加载其js类库:
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>


2.新建一个DataGrid
有两种方法来新建一个DataGrid。下面先说第一种方法。
1)使用table标签来创建
<table  
        url="datagrid24_getdata.php" toolbar="#tb"  
        title="Load Data" iconCls="icon-save"  
        rownumbers="true" pagination="true">  
    <thead>  
        <tr>  
            <th field="itemid" width="80">Item ID</th>  
            <th field="productid" width="80">Product ID</th>  
            <th field="listprice" align="right">List Price</th>  
            <th field="unitcost" align="right">Unit Cost</th>  
            <th field="attr1" width="150">Attribute</th>  
            <th field="status" align="center">Stauts</th>  
        </tr>  
    </thead>  
</table>  


2)使用js代码来创建
<script type="text/javascript">
    $(document).ready(function () {
        $('#historydisplay').datagrid({
            title: '历史数据',
            toolbar: '#search',    //设置工具栏
            fitColumns:true,       //设置列宽度自适应屏幕
            iconCls: 'icon-save',
            url: '@Url.Action("TestData","TCtrl")',
            pageSize:15,        //设置默认分页大小
            pageList:[10,15,20,25,30,35,40,45,50],   //设置分页大小
            columns: [[
            { field: 'StoreNum', title: 'StoreNum', 80 ,align:'center'},
            { field: 'T1', title: 'T1', 80, align: 'center' },
            { field: 'T2', title: 'T2', 80, align: 'center' },
            { field: 'O2', title: 'O2', 80, align: 'center' },
            { field: 'CO2', title: 'CO2', 100, align: 'center' }
            ]],
            pagination: true
        });
    });
</script>


3.在要放置DataGrid的页面添加div
<table id="historydisplay"></table>


4.编写后台代码,对数据进行分页控制
public ActionResult TestData(int page, int rows,int? storenum,DateTime? datefrom,DateTime? dateto) {
            var total = db.TCtrls.OrderBy(x => x.Id).ToList();
            if (storenum != null)
                total = total.Where(x => x.StoreNum == storenum).ToList();
            if ((datefrom != null) && (dateto != null)) {
                DateTime dateBegin = (DateTime)datefrom;
                DateTime dateEnd = (DateTime)dateto;
                total = total.Where(x => x.Time >= dateBegin).Where(x => x.Time <= dateEnd).ToList();
            }
            var result=total.Skip((page - 1)*rows).Take(rows).ToList();
            Dictionary<string, object> json = new Dictionary<string, object>();  
            json.Add("total",total.ToList().Count);
            json.Add("rows",result);
            return Json(json, JsonRequestBehavior.AllowGet);
        }
我此次是用asp.net mvc3实现的,不过大同小异,只要将总数据量total和最后显示的结果数据result封装到JSON对象中即可。


以上部分仅是实现了easyui的分页,下面来总结下easyui的搜索栏实现
在以上基础上添加搜索栏,步骤如下:
1.在相应的DataGrid页面中添加如下代码:
<div style="padding:5px;height:auto">  
    <span>库号:</span>  
    <input />  
    <span>日期:</span>  
    <input />至
    <input />  
    <a href="http://t.zoukankan.com/huangf714-p-5864389.html#" iconCls="icon-search" plain="true" onclick="doSearch()">搜索</a>  
</div>


2.将DataGrid中的toolbar属性设置为搜索栏div的id。
eg:
toolbar: '#search'
见上面DataGrid的2.2


3.添加响应函数
function doSearch() {
        $('#historydisplay').datagrid('load', {
            storenum: $('#storenum').val(),
            datefrom: $('#datefrom').val(),
            dateto: $('#dateto').val()
        });
}


4.添加相应的后台代码,对前端传过去的搜索字段进行处理
具体代码见DataGrid的步骤4

免责声明:文章转载自《(转)EasyUI 分页总结》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇VS2010+Visual Assist XNGINX优化参数下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

MVC中用Jpaginate分页

MVC中用Jpaginate分页 So easy!(兼容ie家族) 看过几款分页插件,觉得Jpaginate比较简约,样式也比较容易的定制,而且体验也比较好,支持鼠标滑动效果。先上效果图: 整个过程很简单,只需要3步 一、引入相关样式和脚本: 1.MVC4中,用了Bundles,你可以把同一个类型多个样式或者脚本的捆绑在一起。调用的时候更加简洁,便于管...

基于ServiceStack.OrmLite框架 代码性能、开发效率皆第一 没有之一

基于ServiceStack.OrmLite框架 代码性能、开发效率皆第一 没有之一 1.此框架方便简洁,便于学习研究。除了基本的增删改查外,还有分页,兼容分页的多表查询,同一业务处理时多次数据库操作仅需要打开一次数据库,反射对象映射赋值,分页返回集合的json封装函数,自定义对象,NLOG日志记录,前端H+框架,sweetalert、Sortable、l...

c#分页工具类,完美实现List分页

using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ProjectProgress.BLL { /// <summary> /// 分页工具类 /// </s...

easyui datagrid分页要点总结

easyui的datagird插件比较好用,也很方便。网上也有很多热的网友贴出了使用代码,但是很少有网友指出在使用过程应该注意的地方,让我实在搞不清分页应该怎么使用。我就说下使用分页功能中要注意的一个小地方。 1、首先你的html得有个table标签 <table id="tt" ></table> 在js页面加载代码中$(docu...

ASP.NET MVC 3.0(十六): MVC 3.0 实例系列之表格数据的分页

ASP.NET MVC 3.0(一): MVC 3.0 的新特性 摘要 ASP.NET MVC 3.0(二): MVC的概念及MVC 3.0开发环境 ASP.NET MVC 3.0(三): 初识MVC的Url映射潜规则Routing ASP.NET MVC 3.0(四): 我要MVC潜规则之配置Routing ASP.NET MVC 3.0(五): 入手C...

jQuery EasyUI教程之datagrid应用

一、利用jQuery EasyUI的DataGrid创建CRUD应用       对网页应用程序来说,正确采集和管理数据通常很有必要,DataGrid的CRUD功能允许我们创建页面来列表显示和编辑数据库记录。本教程将教会你如何运用jQuery EasyUI框架来实现DataGrid的CRUD功能 。 我们会用到如下插件: · datagrid: 列表显示数...