最近用到了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 id="tt" class="easyui-datagrid" style="width:600px;height:250px"  
        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" width="80" align="right">List Price</th>  
            <th field="unitcost" width="80" align="right">Unit Cost</th>  
            <th field="attr1" width="150">Attribute</th>  
            <th field="status" width="60" 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', width: 80 ,align:'center'},
            { field: 'T1', title: 'T1', width: 80, align: 'center' },
            { field: 'T2', title: 'T2', width: 80, align: 'center' },
            { field: 'O2', title: 'O2', width: 80, align: 'center' },
            { field: 'CO2', title: 'CO2', width: 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 id="search" style="padding:5px;height:auto">  
    <span>库号:</span>  
    <input id="storenum" style="border:1px solid #ccc"/>  
    <span>日期:</span>  
    <input class="easyui-datebox" style="width:100px"/>至
    <input class="easyui-datebox" style="width:100px"/>  
    <a href="#" class="easyui-linkbutton" 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 分页总结的更多相关文章

  1. 【技巧】EasyUI分页组件pagination显示项控制

    我们使用easyui分页时,分页组件显示项有很多,默认如下是这样的: 有时候我们并不想显示这么多控制项,我们可以通过属性来控制:如下来自EasyUI官网: 如下写法,在datagrid中使用,如下控制 ...

  2. easyui分页的使用方法

    使用: $("#tt").datagrid("getPager").pagination(option); 例子: $("#tb").dat ...

  3. MVC 使用Jquery EasyUI分页成功

    先上图吧

  4. easyui 分页实现

    1.用datagrid 做分页显示, 依据API样例,最终解决.废话不说,datagrid分页 有一个附加的分页控件 通过在datagrid中设置pagination:true 就会显示分页 当请求是 ...

  5. 后台使用oracle前台使用easyui分页机制

    前台easyui 的datagrid中设置分页属性: pagination:true,//显示分页 pagePosition:'bottom',//分页栏位置 both 上下 bottom.top p ...

  6. easyUI分页实现加搜索功能

    前台页面: js代码: ps:pagination为true时会在table下面加上easyUI的分页. load函数会将查询值传给datagrid并传给后台重新加载. DAO.xml为: 后台代码实 ...

  7. EasyUI 分页 简洁代码

    做分页代码,看到网上很多人实现的方法,那是各种调用,各种获取对象.我很不解,因为Easyui已经给我们了分页的具体实现,为什么有些人要画蛇添足呢. 其实真正的分页,在你的代码中,别人可能都没有注意到, ...

  8. 关于easyUI分页

    首先前台会传来两个参数,分别是rows(一页数据的大小,即一页有多少条数据)和page(第几页),根据这两个参数可以计算出从数据库中从第几 条数据开始取和要取多少条数据.数据取出来后,因为easyUI ...

  9. Struts2与easyui分页查询

    easyui里面分页查询:在easyui框架里面已经进行一些分装,所以我们只要进行后台分页查询即可 web.xml和struts.xml文件的配置的就不需要我多说了,和分页前代码一样,不需要更改: 需 ...

随机推荐

  1. ArcGIS案例学习笔记2_2_等高线生成DEM和三维景观动画

    ArcGIS案例学习笔记2_2_等高线生成DEM和三维景观动画 计划时间:第二天下午 教程:Pdf/405 数据:ch9/ex3 方法: 1. 创建DEM SA工具箱/插值分析/地形转栅格 2. 生成 ...

  2. Uni2D入门

    转载 http://blog.csdn.net/kakashi8841/article/details/17558059 开始 Uni2D增加了一些新的便利的特性给Unity,它们用于推动你2D工作流 ...

  3. mysql 数据库必备命令操作,入门练习一下

    mysql 数据库必备命令操作 show databases: 查看所有的数据库: create database jfedu: 创建名为jfedu数据库: use nihao: 进入jfedu数据库 ...

  4. java网页技术

    About jQuery Getting started with jQuery can be easy or challenging, depending on your experience wi ...

  5. KADEMLIA算法学习

    在上一篇文章中<P2P技术是什么>,我们介绍了P2P技术的特点以及发展历史.在本篇文章中,我们来介绍某一个具体的算法. 如今很多P2P网络的实现都采用DHT的方式实现查找,其中Kademl ...

  6. 2018面向对象程序设计(Java)第7周学习指导及要求

    第7周学习指导及要求(2018.10.11-2018.10.14)   学习目标 深入理解OO程序设计的特征:继承.多态: 熟练掌握Java语言中基于类.继承技术构造程序的语法知识: 利用继承定义类设 ...

  7. Retrofit 打印log时,中文会显示类似%E8%BE%BD字符

    https://blog.csdn.net/honghailiang888/article/details/54289632?utm_source=blogxgwz6 参照Android Retrof ...

  8. 1.3、CDH 搭建Hadoop在安装之前(端口)

    端口 Cloudera Manager,CDH组件,托管服务和第三方组件使用下表中列出的端口.在部署Cloudera Manager,CDH和托管服务以及第三方组件之前,请确保在每个系统上打开这些端口 ...

  9. 安装 pygame,找不到Python version 2.7

    今天在安装pygame时出错,提示“Python version 2.7 required, which was not found in the registry”,经过网上查找资料后发现只需要新建 ...

  10. vue打包后,接口请求404的完美解决方案

    在开发环境中,和后台对接为了解决跨域问题,使用了代理,也就是vue的proxyTable,但是打包放到生产环境中去时,接口请求不到,404,原因是开发环境的代理并不能用到生产环境,但是直接在请求接口是 ...