• toolbar头部工具栏
<script type="text/javascript">
$(function () {
$("#datagrid").datagrid({
url: "<%=homePage%>/testController/datagrid.ajax?type=list",
title: "标题",
iconCls: "icon-save",
pagination: true,
pageSize: 10,
pageList: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
fit: true,
fitColumns: true,//列少的时候,设置为true比较合适
nowrap: false,//false - 单元格数据多的时候进行折行 true - 不管数据有多少,都在一行显示
border: false,
idField: "id",
sortName: "id",
sortOrder: "desc",
columns: [
[
{field: "id", title: "编号", width: 100}
, {field: "name", title: "姓名", width: 100, sortable: true, order: "desc"}
, {field: "password", title: "密码", width: 100}
]
],
toolbar: [
{
iconCls: "icon-add"
, text: "新增"
, handler: function () {
console.log("新增");
}
}, {
iconCls: "icon-remove"
, text: "删除"
, handler: function () {
console.log("删除");
}
}, {
iconCls: "icon-edit"
, text: "编辑"
, handler: function () {
console.log("编辑");
}
}, {
iconCls: "icon-search"
, text: "查询"
, handler: function () {
console.log("查询");
}
}
]
}); }) </script>

toolbar属性,用于设置头部工具栏,效果如下:

但是查询其实不应该做在toolbar上,因为toolbar只能添加按钮,而查询是需要查询提交的

有两种方式

1、在DataGrid组件的上方建立一个<div>,提供一个表单,用于发送查询参数

2、重写toolbar

toolbar: "#toolbar"

toolbar属性值不再是一个数组,而是一个选择器,在选择器指定的目标中,我们重写按钮如下
<div id="toolbar">
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新增</a>
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a>
<a href="#" id="searchbtn" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">查询</a>
<form id="searchForm">
<table>
<tr>
<th>姓名</th>
<td>
<input name="username" type="text"/>
</td>
</tr>
</table>
</form>
</div>

效果图

实现查询功能

$("#searchbtn").click(function(){
console.log("查询");
var searchForm = $("#searchForm").serialize();
console.log("查询条件:"+searchForm);//把这个参数用ajax发送,或者表单提交,然后刷新网格就能够实现查询
});
个人喜欢另一种方式:将数据表格和查询部分放在同一个layout中,一个是center,一个是north,north作为查询部分,一般默认会是隐藏状态的

完整的前端代码如下:

<body class="easyui-layout">
<div data-options="region:'north',title:'查询'" border="false" style="height: 100px" class="datagrid-toolbar">
<form id="schForm" method="post">
<table>
<tr>
<th>姓名</th>
<td>
<input type="text" name="username"/>
</td>
</tr>
<tr>
<th>时间段</th>
<td>
<input name="startTime" class="easyui-datetimebox" editable="false"/>
---
<input name="endTime" class="easyui-datetimebox" editable="false"/>
<a href="#" id="schbt" class="easyui-linkbutton">查询</a>
<a href="#" id="rstbt" class="easyui-linkbutton">重置</a>
</td> </tr>
</table>
</form>
</div>
<div data-options="region:'center'" fit="true" border="false">
<table id="datagrid"></table>
</div>
</body>
//默认不显示查询条件
$("body").layout('collapse', 'north');
$("#schbt").click(function () {
console.log("查询"); //这个方法可以封装起来
var v1 = $("#schForm").serialize();
v1 = decodeURIComponent(v1, true);//解决序列化后的乱码问题
console.log("v1:" + v1);
var string = v1.split('&');
var res = {};
for (var i = 0; i < string.length; i++) {
var str = string[i].split('=');
console.log(str);
res[str[0]] = str[1];
}
console.log(res);
$("#datagrid").datagrid("load", res);
});

$("#rstbt").click(function () {
console.log("重置");//将Form中的数据清空即可
})
  • 表单重置
$("#rstbt").click(function () {
console.log("重置");//将Form中的数据清空即可 $("#schForm :input")
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected'); })

数据表格 - DataGrid - 查询的更多相关文章

  1. JQuery Easy Ui dataGrid 数据表格 ---制作查询下拉菜单

    JQuery Easy Ui dataGrid 数据表格 数据表格 - DataGrid 继承$.fn.panel.defaults,使用$.fn.datagrid.defaults重载默认值.. 数 ...

  2. 向DataGrid数据表格增加查询搜索框

    向DataGrid数据表格增加查询搜索框 效果如下: js代码: $(function(){ var dg = $('#dg').datagrid({ url:"${pageContext. ...

  3. [转载]EasyUI中数据表格DataGrid添加排序功能

    我们这里演示的是EasyUI数据表格DataGrid从服务器端排序功能,因为觉的本地数据排序没有多大的作用,一般我们DataGrid不会读取全部数据,只会读取当前页的数据,所以本地数据排序也只是对当前 ...

  4. easyUI 数据表格datagrid的使用

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  5. 解决:layUI数据表格+简单查询

    解决:layUI数据表格+简单查询 最近在用layui写项目,在做到用户查询时,发现在layui框架里只有数据表格,不能增加查询.于是自己摸索了一下,写个笔记记录一下. 我想要的效果: 1.定义查询栏 ...

  6. jquery easy ui 1.3.4 数据表格(DataGrid)(8)

    8.1.创建DataGrid html代码 <table id="dg"></table> $("#dg").datagrid({ // ...

  7. easyui框架--基础篇(一)-->数据表格datagrid(php与mysql交互)

      前  言  php  easyui框架--本篇学习主要是 easyui中的datagrid(数据表格)框架. 本篇学习主要通过讲解一段代码加GIF图片学习datagrid(数据表格)中的一些常用属 ...

  8. 数据表格datagrid内容整理

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  9. 数据表格 - DataGrid - 列表显示

    <%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding=& ...

随机推荐

  1. php实现设计模式之 装饰模式

    <?php /* * 装饰模式:在不必改变原类文件和使用继承的情况下,动态地扩展一个对象的功能.它是通过创建一个包装对象,也就是装饰来包裹真实的对象. * * 角色 * 抽象构件(Compone ...

  2. Lind.DDD.Manager里的3,7,15,31,63,127,255,511,1023,2047

    回到目录 进制 我是一个程序猿,我喜欢简单的数字,十进制如何,数字太多,有10种数字组成,但由于它广为人知,所有使用最为广泛,人们的惯性思维培养了十进制,并说它是最容易被计算的数字,事实上,在计算机里 ...

  3. (转)SQL 优化原则

    一.问题的提出 在应用系统开发初期,由于开发数据库数据比较少,对于查询SQL语句,复杂视图的的编写等体会不出SQL语句各种写法的性能优劣,但是如果将应用 系统提交实际应用后,随着数据库中数据的增加,系 ...

  4. Egret白鹭H5小游戏开发入门(二)

    前言: 昨天的文章中简单的介绍了Egret白鹭引擎从安装到基本的使用配置等问题,今天着重介绍H5小游戏开发的起步阶段,如Wing面板的使用,素材的处理,类的说明,开始布局等等. 整体概况: 根据上一篇 ...

  5. DevExpress TreeList使用心得

    来自:http://www.cnblogs.com/sndnnlfhvk/archive/2011/05/15/2046920.html 最近做项目新增光纤线路清查功能模块,思路和算法已经想好了,些代 ...

  6. 去除GridView选中时的蓝色背景

    解决办法: android:listSelector="#00000000" android:listSelector="@android:color/transpare ...

  7. 用Kotlin开发Android应用(I):介绍

    关于Kotlin,网上已有一些介绍的文章,包括Antonio Leiva的这组blog翻译稿.不过,我还是想跟进它们.翻译它们,以锻炼自己的英文翻译.各位高手发现问题,请及时“拍砖”. 原文题目:Ko ...

  8. 用UILocalNotification实现一个闹钟(Swift)

    之前项目需求要实现一个闹钟,github上找了半天发现都是很旧的代码了,所以就准备自己写一个,刚好最近在学习Swift,就用Swift写了一个demo放在这里:https://github.com/P ...

  9. 了解HTML 元素分类

    HTML中包含大量的标签, 这些标签在我们使用中发现会有小小的差别, 有的标签用了之后不会有太大的布局变化, 只是语义化, 而有的标签却会重起一行, 相当于自己回车了一次, 这就是不同标签元素的分类不 ...

  10. 在 CentOS7 之部署 Redis3

    CentOS7 之 Redis3 学习笔记 1 Redis 官网: http://www.redis.io/ 2 Redis 的下载地址: http://download.redis.io/relea ...