数据表格 - DataGrid - 查询

  • 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中的数据清空即可})
时间: 2024-08-27 00:16:20

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

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

向DataGrid数据表格增加查询搜索框 效果如下: js代码: $(function(){ var dg = $('#dg').datagrid({ url:"${pageContext.request.contextPath}/OfferServlet",//servlet路径 columns:[[ {field:'offerid',title:'商品ID',width:100}, {field:'offername',title:'商品名称',width:100}, {field

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

我们这里演示的是EasyUI数据表格DataGrid从服务器端排序功能,因为觉的本地数据排序没有多大的作用,一般我们DataGrid不会读取全部数据,只会读取当前页的数据,所以本地数据排序也只是对当前页的数据进行排序,不是我们想要用效果. 下面开始演示从服务器端排序功能. 第一步,启用EasyUI DataGrid的排序功能: 具体就是为列设置sortable属性,如下: { field: "SOID", title: "订单单号", width: "80

easyui框架--基础篇(一)--&gt;数据表格datagrid(php与mysql交互)

  前  言  php  easyui框架--本篇学习主要是 easyui中的datagrid(数据表格)框架. 本篇学习主要通过讲解一段代码加GIF图片学习datagrid(数据表格)中的一些常用属性,还有与之相关的dialog(对话窗)和texbobox(文本框)的一些常用属性,希望对读者有帮助. 本篇主要分为两个部分讲解: ① 前端PHP代码编写--框架搭建与数据调用 ② 数据库的数据内容与后台数据连接,后台数据传输到前台 以下所有代码HBuider中建立PHP文件实施.(前提php文件可

数据表格datagrid内容整理

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <

easyUI数据表格datagrid之笔记

1.用ajax获取数据库数据 /**========================================= * 读取数据库信息,使用ajax的load方法 */function getMediaInfo(){ var orgInfo=[]; $.ajax({ url:baseCtx+"/media/getMediaInfo.action", data:{}, type : 'post', async : false, dataType : "json",

easyUI数据表格datagrid之笔记2

/**========================================= * 追加在表格尾部 */function append(){ editIndex = $('#dg').datagrid('getRows').length-1; //if (endEditing()){ $('#dg').datagrid('appendRow',{ MEDIA_ID:editIndex, MEDIA_NAME:'testmedia', MEDIA_DOMAIN:'http://ceshi

easyUI数据表格datagrid之分页

一.分页函数 /**========================================= * 分页函数 */function pagerFilter(data) { if(typeof data.length == 'number' && typeof data.splice == 'function') { // is array data = { total: data.length, rows: data } } var dg = $(this); var opts =

数据表格,查询、导出共用一个form表单,实现文件流方式下载

在开发中遇到问题是这样的: 在维护老的管理系统的过程中,老板说让加导出功能:项目中,查询的筛选条件是用的表单提交的方式写的. 解决方案有两种: 一.用ajax方式导出 var array = $('#frmSearch').serialize(); 获得表单数据后,用post方式提交给服务器,服务器返回文件所存在的网络地址,然后用windows.open()的方式下载文件 但是我希望文件下载后,能够把文件删除了:用上边方式就不太合适了,不能及时删除旧文件,于是想出下面的方式: 二.文件流的方式下

JQuery EasyUI 学习——Struts2与EasyUI DataGrid数据表格结合使用显示数据库数据

因为EasyUI DataGrid只要取出后台传过来的一定格式的JSON数据,就可以在前台页面数据表格中,以一定形式显示数据库中的数据.此处,我们使用Struts2框架整合DataGrid,实现数据的显示. 一.页面内容 为了在页面中显示数据库中字段内容,需要定义一个table,通过EasyUI内部设计,自动显示数据,如下: <%@ page language="java" import="java.util.*" pageEncoding="UTF