效果:

html代码:

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

JS代码:

  • toolbar使用css加载。其余看代码,看注释。
  1. $(function () {
  2.  
  3. //格式化日期输出样式
  4. $('#time_from, #time_to').datebox({
  5. formatter: function (date) { return date.getFullYear() + '/' + (date.getMonth() + ) + '/' + date.getDate(); },
  6. });
  7.  
  8. //Datagrid设置
  9. $('#tab').datagrid({
  10.  
  11. //===================================== 样式 ===============================================//
  12. width: ,//宽度
  13. title: '信息列表',//标题名
  14. iconCls: 'icon-search',//图标
  15. singleSelect: true,//是否单选
  16. striped: true,//是否开启斑马线
  17. fitColumns: false,//是否自适应宽度(出现滚动条)
  18. loadMsg: '正在努力加载,请稍后………………',//显示加载提示信息
  19. rownumbers: true,//显示行号
  20. //showHeader: false,//是否显示行头(标题)
  21. //showFooter:false,//显示行尾,默认情况下不显示,要在后台使用json数据传递
  22. //==========================================================================================//
  23.  
  24. //============================= 加载数据,要显示的字段 =========================================//
  25. //要加载的数据
  26. url: "../Json/datagridjson.ashx",
  27. //要显示的列
  28. columns: [[
  29. {
  30. field: 'id',
  31. title: '编号',
  32. align: 'center',//标题和内容居中
  33. resizable: false,//不允许改变大小
  34. //hidden:true,//隐藏该列
  35. width: ,//所有字段设置成100,起到自动平均分配大小的作用
  36. },
  37. {
  38. field: 'name',
  39. title: '姓名',
  40. width: ,//所有字段设置成100,起到自动平均分配大小的作用
  41. halign: 'center',//仅标题居中
  42.  
  43. //显示数据的时候,格式化数据
  44. formatter: function (value, row, index) {
  45. return '[ ' + value + ' ]';
  46. },
  47. },
  48. {
  49. field: 'sex',
  50. title: '性别',
  51. width: ,//所有字段设置成100,起到自动平均分配大小的作用
  52. },
  53. //在字段中使用排序,每点击一次,都会向后台POST要排序的字段和正序还是倒序排列。
  54. {
  55. field: 'createtime',
  56. title: '创建时间',
  57. width:,//所有字段设置成100,起到自动平均分配大小的作用
  58. sortable: true,//允许排序
  59. }
  60. ]],
  61. //==========================================================================================//
  62.  
  63. //===================================== 分页 ===============================================//
  64. //显示分页控件栏
  65. pagination: true,
  66. pageNumber: ,//初始化的时候在第几页
  67. pageSize: ,//,每页显示的条数
  68. pageList: [, , ],//每页显示的条数
  69. //==========================================================================================//
  70.  
  71. //===================================== 排序 ===============================================//
  72. //通过POST传递到后台,然后进行排序。
  73. sortName: 'createtime',
  74. sortOrder: 'desc',
  75. //==========================================================================================//
  76.  
  77. //===================================== 按钮 ===============================================//
  78. toolbar: '#tb',
  79. //==========================================================================================//
  80.  
  81. });
  82.  
  83. //添加
  84. $('#add').click(function () {
  85. alert('添加按钮');
  86. });
  87.  
  88. //修改
  89. $('#edit').click(function () {
  90. alert('编辑按钮');
  91. });
  92.  
  93. //删除
  94. $('#remove').click(function () {
  95. alert('删除按钮');
  96. });
  97.  
  98. //查询
  99. $('#search').click(function () {
  100. $('#tab').datagrid('load', {
  101. searchvalue: $.trim($('input[name="name"]').val()),
  102. time_from: $.trim($('input[name="time_from"]').val()),
  103. time_to: $.trim($('input[name="time_to"]').val()),
  104. });
  105. });
  106.  
  107. })

后台一般处理程序接收:

  • 查询代码。
  • 底部统计总条数代码。
    1.  
    1. rom Tb_person "+connect+" order by
    1.  
    1. time from Tb_person " + connect + " ) as a where a.
  1. public void ProcessRequest(HttpContext context)
  2. {
  3. context.Response.ContentType = "application/json";
  4.  
  5. //接受前台传递来的页数和每页显示的条数
  6. //前台开启分页之后,传递来的参数
  7. int pageIndex = Convert.ToInt32(context.Request["page"]);
  8. int pagenumber = Convert.ToInt32(context.Request["rows"]);
  9.  
  10. //接收排序字段
  11. string sortfield = context.Request["sort"];
  12. string sortDescOrasc = context.Request["order"];
  13.  
  14. //------------------------------------------搜索-----------------------------------------
  15. string connect = "";
  16. string searchvalue = "";
  17. string time_from = "";
  18. string time_to = "";
  19.  
  20. if (context.Request["searchvalue"] != null && context.Request["searchvalue"] != "")
  21. {
  22. searchvalue = "name like '%" + context.Request["searchvalue"] + "%' and ";
  23. connect += searchvalue;
  24. }
  25.  
  26. if (context.Request["time_from"] != null && context.Request["time_from"] != "")
  27. {
  28. time_from = "createtime>='" + context.Request["time_from"].Replace('/','-') + "' and ";
  29. connect += time_from;
  30. }
  31.  
  32. if (context.Request["time_to"] != null && context.Request["time_to"] != "")
  33. {
  34. time_to = "createtime<='" + context.Request["time_to"].Replace('/', '-') + "' and ";
  35. connect += time_to;
  36. }
  37.  
  38. if (connect != "")
  39. {
  40. connect = " where " + connect.Substring(, connect.Length - );
  41. }
  42. //--------------------------------------------------------------------------------------------
  43.  
  44. //存储数据
  45. DataTable dt = new DataTable();
  46.  
  47. if (pageIndex == )
  48. {
  49. //加载第一页
  50. string pageIndexOne = "select top " + pagenumber + " id, name, sex, createtime from Tb_person "+connect+" order by " + sortfield + " " + sortDescOrasc + "";
  51. //获取并转换为JSON数据
  52. dt = SQLHelper.ExecuteTable(pageIndexOne, CommandType.Text);
  53. }
  54. else if (pageIndex != )
  55. {
  56. //加载非第一页
  57. 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 + "";
  58. //获取并转换为JSON数据
  59. dt = SQLHelper.ExecuteTable(pageIndexNotOne, CommandType.Text);
  60. }
  61. else { }
  62.  
  63. //将datatable转换为json
  64. //在返回的JSON数据中,加入total属性(总记录数)
  65. //那么他就会在加载的时候,显示总记录数。
  66. //显示的格式是【 {"total":12, "rows":"[{},{},{}]"} 】,rows内为JSON数据。
  67. //计算总条数(同时可以统计,使用关键字查询之后的条数)
  68. int totalnumber = (int)SQLHelper.ExcuteScalar("select count(*) from Tb_person " + connect + "", CommandType.Text);
  69. //返回数据
  70. string strjson = "{\"total\":" + totalnumber + ", \"rows\":" + DatatableToJson.ToJson(dt) + "}";
  71.  
  72. context.Response.Write(strjson);
  73. }

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. android面试题之三

    十一.对一些资源以及状态的操作保存,最好是保存在生命周期的哪个函数中进行? 若在onPause()中进行保存,相应需要在onResume()中进行恢复. 若在onStop()中进行保存,相应需要在on ...

  2. Objective-C基础教程读书笔记(7)

    第7章 深入了解Xcode Xcode是一个很好用的工具,有很多强大的功能,不过并不是所有的功能都易于发现.如果你打算长期使用这个强大的工具,就肯定要尽可能多了解它.本章将介绍一些Xcode编辑器的使 ...

  3. UVA 10341 Solve It 解方程 二分查找+精度

    题意:给出一个式子以及里面的常量,求出范围为[0,1]的解,精度要求为小数点后4为. 二分暴力查找即可. e^(-n)可以用math.h里面的exp(-n)表示. 代码:(uva该题我老是出现Subm ...

  4. 一次搞定cocos2d-x的 Android.mk 文件

    cocos2d-x 打 android 包时要修改 Android.mk 文件,但每次修改很麻烦,如果源文件很多的话就坑死了,也可以写一个脚本来自动生成这个文件,但每次还要重新生成一下,将其修改下面的 ...

  5. 将其它图片格式转为.eps格式

    假设是用origin的话就不存在这个问题. 倘若你是用excel绘图的话. 1.先将excel导出为.pdf文件 2.用Adobe Acrobat Pro 打开pdf,用其它的pdf软件貌似不行 3. ...

  6. [POJ 1521]--Entropy(哈夫曼树)

    题目链接:http://poj.org/problem?id=1521 Entropy Time Limit: 1000MS    Memory Limit: 10000K Description A ...

  7. AppCode3 常用 设置 及 快捷键 (持续更新)

    以下设置都可以通过 设置中的搜索框 进行关键字搜索 0, 打开Project 设置 Command + ; 1, 打开设置快捷键 Command + , 2, 显示行号 Editor -> Ap ...

  8. 关于RtlInitUnicodeString感想

    01 VOID RtlInitUnicodeString (OUT PUNICODE_STRING DestinationString,IN PCWSTR SourceString OPTIONAL) ...

  9. hdu1397(素数组和成偶数的个数 用 标记法)

    Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...

  10. CentOS 漏洞修补

    以前没注意 今后得实时更新系统漏洞和补丁了! 1.Bash软件安全漏洞检测及解决方案 http://netsecurity.51cto.com/art/201409/452322.htm