×
jQuery EasyUI 教程jQuery EasyUI 简介

jQuery EasyUI 应用

创建 CRUD 应用创建 CRUD 数据网格创建 CRUD 表单的创建 RSS Feed 阅读器

jQuery EasyUI 拖放

基本的拖动和放置创建拖放的购物车创建学校课程表

jEasyUI 菜单与按钮

创建简单的菜单创建链接按钮创建菜单按钮创建分割按钮

jQuery EasyUI 布局

为网页创建边框布局在面板中创建复杂布局创建折叠面板创建标签页(Tabs)动态添加标签页(Tabs)添加自动播放标签页(Tabs)创建 XP 风格左侧面板

jQuery EasyUI 数据网格

转换 HTML 表格为数据网格取得选中行数据添加查询功能添加工具栏创建复杂工具栏设置冻结列动态改变列格式化列设置排序自定义排序创建列组合添加复选框自定义分页启用行内编辑扩展编辑器列运算合并单元格创建自定义视图创建页脚摘要条件设置行背景颜色创建属性网格扩展行显示细节创建子网格使用虚拟滚动视图显示海量数据添加分页组件

jQuery EasyUI 窗口

创建简单窗口自定义窗口工具栏窗口与布局创建对话框自定义对话框

jQuery EasyUI 树形菜单

使用标记创建树形菜单创建异步树形菜单树形菜单添加节点创建带复选框的树形菜单树形菜单拖放控制树形菜单加载父/子节点创建基础树形网格创建复杂树形网格树形网格动态加载树形网格添加分页树形网格惰性加载节点

jQuery EasyUI 表单

创建异步提交表单表单验证创建树形下拉框格式化下拉框过滤下拉数据网格

jQuery EasyUI 参考手册

jQuery EasyUI 插件jQuery EasyUI 扩展

jQuery EasyUI 数据网格 – 添加查询功能


本实例演示如何从数据库得到数据,并将它们显示在数据网格(datagrid)中。然后演示如何根据用户输入的搜索关键词搜寻显示结果。

创建数据网格(DataGrid)

创建带有分页功能的数据网格(datagrid),然后添加工具栏到其中。


<table id="tt" class="easyui-datagrid" style="width:600px;height:250px"
url="datagrid24_getdata.php" toolbar="#tb"
title="Load Data" iconCls="icon-save"
rownumbers="true" pagination="true">
<thead>
<tr>
<th field="itemid" width="80">Item ID</th>
<th field="productid" width="80">Product ID</th>
<th field="listprice" width="80" align="right">List Price</th>
<th field="unitcost" width="80" align="right">Unit Cost</th>
<th field="attr1" width="150">Attribute</th>
<th field="status" width="60" align="center">Stauts</th>
</tr>
</thead>
</table>

工具栏定义如下:


<div id="tb" style="padding:3px">
<span>Item ID:</span>
<input id="itemid" style="line-height:26px;border:1px solid #ccc">
<span>Product ID:</span>
<input id="productid" style="line-height:26px;border:1px solid #ccc">
<a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">Search</a>
</div>

当用户输入查询值并按下查询按钮时,'doSearch' 函数将被调用:


function doSearch(){
$('#tt').datagrid('load',{
itemid: $('#itemid').val(),
productid: $('#productid').val()
});
}

上面的代码调用了 'load' 方法来加载新的数据网格(datagrid)数据。我们需要传递 'itemid' 和 'productid' 参数到服务器。

服务器端代码


include 'conn.php';

$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$itemid = isset($_POST['itemid']) ? mysql_real_escape_string($_POST['itemid']) : '';
$productid = isset($_POST['productid']) ? mysql_real_escape_string($_POST['productid']) : '';

$offset = ($page-1)*$rows;

$result = array();

$where = "itemid like '$itemid%' and productid like '$productid%'";
$rs = mysql_query("select count(*) from item where " . $where);
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];

$rs = mysql_query("select * from item where " . $where . " limit $offset,$rows");

$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}
$result["rows"] = $items;

echo json_encode($result);

下载 jQuery EasyUI 实例

jeasyui-datagrid-datagrid24.zip


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)