• 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. Castle Windsor常用介绍以及其在ABP项目的应用介绍

    最近在研究ABP项目,有关ABP的介绍请看阳光铭睿 博客,ABP的DI和AOP框架用的是Castle Windsor下面就对Castle Windsor项目常用方法介绍和关于ABP的使用总结 1.下载 ...

  2. 更新整理本人所有博文中提供的代码与工具(Java,2013.11)

    为了更方便地管理博文中涉及的各种代码与工具资源,现在把这些资源迁移到 Google Code 中,有兴趣者可前往下载. Java 1.<高效 Java Web 应用开发框架 JessMA v3. ...

  3. C#综合揭秘——通过修改注册表建立Windows自定义协议

    引言 本文主要介绍注册表的概念与其相关根项的功能,以及浏览器如何通过连接调用自定义协议并与客户端进行数据通信.文中讲及如何通过C#程序.手动修改.安装项目等不同方式对注册表进行修改.其中通过安装项目对 ...

  4. JAVA的POI操作Excel

    1.1Excel简介 一个excel文件就是一个工作簿workbook,一个工作簿中可以创建多张工作表sheet,而一个工作表中包含多个单元格Cell,这些单元格都是由列(Column)行(Row)组 ...

  5. 2015元旦来个炫的html5特效

    效果网址:http://keleyi.com/keleyi/phtml/html5/5.htm 代码: <!DOCTYPE html> <html xmlns="http: ...

  6. html5+Canvas实现酷炫的小游戏

    最近除了做业务,也在尝试学习h5和移动端,在这个过程中,学到了很多,利用h5和canvas做了一个爱心鱼的小游戏.点这里去玩一下 PS: 貌似有点闪屏,亲测多刷新两下就好了==.代码在本地跑都不会闪, ...

  7. SharePoint Framework:下一代开发方式

    SharePoint Framework(SPFx),是页面 和Webpart的模型,完全支持本地开发(即完全可以脱离SharPoint环境在本地进行开发),听起来是不是很高级呢,早期SharePoi ...

  8. Html5的一些基础知识

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

  9. Golang(笔记) 面向对象

    package main import ( "fmt" ) //对象定义 type Rect struct{ x,y float64 width ,height float64 } ...

  10. Objective-C Runtime 运行时之四:Method Swizzling

    理解Method Swizzling是学习runtime机制的一个很好的机会.在此不多做整理,仅翻译由Mattt Thompson发表于nshipster的Method Swizzling一文. Me ...