效果:

html代码:

  • 使用css加载的方式,所以要在写html代码,也可以使用js操作。
<div>
<!--使用JS加载方式-->
<table id="tab"></table> <!--按钮--->
<div id="tb">
<div style ="padding:5px;">
<a id ="add" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add',">添加</a>
<a id ="edit" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit',">修改</a>
<a id ="remove" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove',">删除</a>
</div>
<div style ="padding-left:10px;padding-bottom:10px;">
搜索姓名(可以模糊查询):<input id ="name" name ="name" type ="text" class="textbox" style ="width:130px;" />
查询时间 从:<input id ="time_from" name ="time_from" type ="text" class ="easyui-datebox" style ="width:130px;"/>
到:<input id ="time_to" name ="time_to" type ="text" class ="easyui-datebox" style ="width:130px;"/>
<a id ="search" href ="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'," style ="margin-left:20px; padding:0 10px 0 10px;">搜索</a>
</div>
</div>
</div>

JS代码:

  • toolbar使用css加载。其余看代码,看注释。
$(function () {

        //格式化日期输出样式
$('#time_from, #time_to').datebox({
formatter: function (date) { return date.getFullYear() + '/' + (date.getMonth() + ) + '/' + date.getDate(); },
}); //Datagrid设置
$('#tab').datagrid({ //===================================== 样式 ===============================================//
width: ,//宽度
title: '信息列表',//标题名
iconCls: 'icon-search',//图标
singleSelect: true,//是否单选
striped: true,//是否开启斑马线
fitColumns: false,//是否自适应宽度(出现滚动条)
loadMsg: '正在努力加载,请稍后………………',//显示加载提示信息
rownumbers: true,//显示行号
//showHeader: false,//是否显示行头(标题)
//showFooter:false,//显示行尾,默认情况下不显示,要在后台使用json数据传递
//==========================================================================================// //============================= 加载数据,要显示的字段 =========================================//
//要加载的数据
url: "../Json/datagridjson.ashx",
//要显示的列
columns: [[
{
field: 'id',
title: '编号',
align: 'center',//标题和内容居中
resizable: false,//不允许改变大小
//hidden:true,//隐藏该列
width: ,//所有字段设置成100,起到自动平均分配大小的作用
},
{
field: 'name',
title: '姓名',
width: ,//所有字段设置成100,起到自动平均分配大小的作用
halign: 'center',//仅标题居中 //显示数据的时候,格式化数据
formatter: function (value, row, index) {
return '[ ' + value + ' ]';
},
},
{
field: 'sex',
title: '性别',
width: ,//所有字段设置成100,起到自动平均分配大小的作用
},
//在字段中使用排序,每点击一次,都会向后台POST要排序的字段和正序还是倒序排列。
{
field: 'createtime',
title: '创建时间',
width:,//所有字段设置成100,起到自动平均分配大小的作用
sortable: true,//允许排序
}
]],
//==========================================================================================// //===================================== 分页 ===============================================//
//显示分页控件栏
pagination: true,
pageNumber: ,//初始化的时候在第几页
pageSize: ,//,每页显示的条数
pageList: [, , ],//每页显示的条数
//==========================================================================================// //===================================== 排序 ===============================================//
//通过POST传递到后台,然后进行排序。
sortName: 'createtime',
sortOrder: 'desc',
//==========================================================================================// //===================================== 按钮 ===============================================//
toolbar: '#tb',
//==========================================================================================// }); //添加
$('#add').click(function () {
alert('添加按钮');
}); //修改
$('#edit').click(function () {
alert('编辑按钮');
}); //删除
$('#remove').click(function () {
alert('删除按钮');
}); //查询
$('#search').click(function () {
$('#tab').datagrid('load', {
searchvalue: $.trim($('input[name="name"]').val()),
time_from: $.trim($('input[name="time_from"]').val()),
time_to: $.trim($('input[name="time_to"]').val()),
});
}); })

后台一般处理程序接收:

  • 查询代码。
  • 底部统计总条数代码。
  • 
    
    rom Tb_person "+connect+"  order by 
  • 
    
    time from Tb_person " + connect + " ) as a where a.
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json"; //接受前台传递来的页数和每页显示的条数
//前台开启分页之后,传递来的参数
int pageIndex = Convert.ToInt32(context.Request["page"]);
int pagenumber = Convert.ToInt32(context.Request["rows"]); //接收排序字段
string sortfield = context.Request["sort"];
string sortDescOrasc = context.Request["order"]; //------------------------------------------搜索-----------------------------------------
string connect = "";
string searchvalue = "";
string time_from = "";
string time_to = ""; if (context.Request["searchvalue"] != null && context.Request["searchvalue"] != "")
{
searchvalue = "name like '%" + context.Request["searchvalue"] + "%' and ";
connect += searchvalue;
} if (context.Request["time_from"] != null && context.Request["time_from"] != "")
{
time_from = "createtime>='" + context.Request["time_from"].Replace('/','-') + "' and ";
connect += time_from;
} if (context.Request["time_to"] != null && context.Request["time_to"] != "")
{
time_to = "createtime<='" + context.Request["time_to"].Replace('/', '-') + "' and ";
connect += time_to;
} if (connect != "")
{
connect = " where " + connect.Substring(, connect.Length - );
}
//-------------------------------------------------------------------------------------------- //存储数据
DataTable dt = new DataTable(); if (pageIndex == )
{
//加载第一页
string pageIndexOne = "select top " + pagenumber + " id, name, sex, createtime from Tb_person "+connect+" order by " + sortfield + " " + sortDescOrasc + "";
//获取并转换为JSON数据
dt = SQLHelper.ExecuteTable(pageIndexOne, CommandType.Text);
}
else if (pageIndex != )
{
//加载非第一页
string pageIndexNotOne = @"select id, name, sex, createtime from (select ROW_NUMBER() over(order by " + sortfield + " " + sortDescOrasc + ") as rownum, id, name, sex, createtime from Tb_person " + connect + " ) as a where a.rownum > " + (pageIndex - ) * pagenumber + " and a.rownum <= " + pageIndex * pagenumber + "";
//获取并转换为JSON数据
dt = SQLHelper.ExecuteTable(pageIndexNotOne, CommandType.Text);
}
else { } //将datatable转换为json
//在返回的JSON数据中,加入total属性(总记录数)
//那么他就会在加载的时候,显示总记录数。
//显示的格式是【 {"total":12, "rows":"[{},{},{}]"} 】,rows内为JSON数据。
//计算总条数(同时可以统计,使用关键字查询之后的条数)
int totalnumber = (int)SQLHelper.ExcuteScalar("select count(*) from Tb_person " + connect + "", CommandType.Text);
//返回数据
string strjson = "{\"total\":" + totalnumber + ", \"rows\":" + DatatableToJson.ToJson(dt) + "}"; context.Response.Write(strjson);
}

EasyUI - DataGrid 组建 - [ 搜索功能 ]的更多相关文章

  1. EasyUI - DataGrid 组建 - [ 新增功能 ]

    效果: html代码: <div> <!--使用JS加载方式--> <table id="tab"></table> <!-- ...

  2. EasyUI - DataGrid 组建 - [ 样式功能 ]

    效果显示: 同上次博文效果. html代码: 同上次博文代码. js代码: align: 'center',//标题和内容居中 resizable: false,//不允许改变大小 //hidden: ...

  3. EasyUI - DataGrid 组建 - [ 排序功能 ]

    效果: 红框的字段看,为设置了,列排序,向后台Post数据sort/order. 原理:向后台POST数据,sort/post数据. html代码: <table id="tab&qu ...

  4. easyui datagrid client搜索、分页、排序

    easyui datagrid的排序默认是server端排序.能够用sorter实现client排序[2].client分页可用filter实现[3].client搜索相同能够用filter实现. 不 ...

  5. EasyUI - DataGrid 组建 - [ 删除,修改 ]

    效果: html代码: <div style="padding-top: 50px; width: 800px; margin: 0 auto;"> <!--使用 ...

  6. EasyUI - DataGrid 组建 - [ 组件加载和分页 ]

    效果: 原理:通过POST传递到数据后台字段. 此时上传的参数,page:当前页数,rows:每页显示的页数. 有此两项参数,计算取出数据条数. 通过后台接受参数,进行处理并返回抽取的数据. html ...

  7. 【第十一篇】这一篇来说说MVC+EF+easyui datagrid的查询功能

    老规矩 直接上代码 <form class="form-horizontal"> <div class="box-body"> < ...

  8. easyui datagrid 行编辑功能

    datagrid现在具有行编辑能力了,使用时只须在columns中为需要编辑的列添加一个editor属性,编辑保存时同时具有数据校验能力. 看一个例子效果图: 代码如下: $('#tt').datag ...

  9. easyui combobox开启搜索自动完成功能

    combo.json [{ "id":-1, "text":" ", "spell":"" },{ ...

随机推荐

  1. fedora21安装无线驱动

    来源:http://www.2cto.com/os/201202/120249.html 一.导入rpmfushion源,使用第三方yum 源: su -c 'yum localinstall --n ...

  2. 中国A股市场缘何遭遇9连跌?

    端午长假刚过,当投资者对“红六月”预期信心满满的时候,A股市场却遭遇了诡异的跌势,截止6月17日收盘,A股出现了罕见的“9连跌”.不仅上证综指失守2200点年线整数位,深证成指跌幅则高达3%以上,而且 ...

  3. vs2013内置IISExpress相关问题

    问题描述,以前做的程序迁移到vs2013后出现500.22问题. HTTP 错误 500.22 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设 ...

  4. 写一方法用来计算1+2+3+...n,其中n作为参数输入,返回值可以由方法名返回,也可以由参数返回

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. [Swust OJ 179]--火柴棍(找规律)

    题目链接:http://acm.swust.edu.cn/problem/0179/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  6. [POJ 2184]--Cow Exhibition(0-1背包变形)

    题目链接:http://poj.org/problem?id=2184 Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  7. Net Core在Linux环境

    Net Core在Linux环境 基础环境和相关软件准备 1.CentOS7.1 64位系统(或者其他CentOS版本的64位系统) 2.WinSCP软件(主要是方便管理和编辑Linux系统的文件) ...

  8. 带符号的char类型取值范围为什么是-128——127

    以前经常看到带符号的char类型取值范围是-128——127,今天突然想为什么不是-127——127,-128是怎么来的? 127好理解,char类型是8位,最高位是符号位,0正1负,所以011111 ...

  9. YARN & HDFS2 安装和配置Kerberos

    今天尝试在Hadoop 2.x开发集群上配置Kerberos,遇到一些问题,记录一下 设置hadoop security core-site.xml <property> <name ...

  10. 查看电脑已安装的Jdk的位数

    查看自己电脑已安装的Jdk的位数的方法: public class ShowJdkBit { public static void main(String[] args) { String arch ...