教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 jQuery easyui datagrid动态查询数据实例讲解

jQuery easyui datagrid动态查询数据实例讲解

发布时间:2013-11-12   编辑:jiaochengji.com
接下来将从前台提交查询条件,从MSSQL返回json数据的一个事例来讲解一下datagrid动态查询数据,感兴趣的你可不要错过了哈,希望本文可以帮助到你
该插件组小巧使用方便,以下是一个从前台提交查询条件,从MSSQL返回json数据的一个事例
HTML前端代码
复制代码 代码如下:

<?php
include_once("auth.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="/inc/js/EasyUI/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/inc/js/EasyUI/themes/icon.css">
<script type="text/javascript" src="/inc/js/EasyUI/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="/inc/js/EasyUI/jquery.easyui.min.js"></script>
<script>
function FindData(){
$('#mytable').datagrid('load',{
PersonCode:$('#PersonCode').val(),
KQYM:$('#KQYM').val()}
);
}
</script>
</head>
<body>
<table id='mytable' class="easyui-datagrid" style="width:600px;height=500px"
url="loadgriddata_get.php" title="请输入查询条件"
rownumbers="true" toolbar="#searchtool" loadMsg="正在查询...">
<thead>
<tr>
<th field="PersonCode" Width="80">工号</th>
<th field="MyName" width="80">姓名</th>
<th field="KQDate" width="100">考勤日期</th>
<th field="MyWeek" width="80">星期</th>
<th field="KQMemo" width="200">打卡时间</th>
</tr>
</thead>
</table>

<div id="searchtool" style="padding:5px">
<span>工号:</span><input type="text" id="PersonCode" value="" size=10 />
<span>考勤年月:</span><input type="text" id="KQYM" value="" size=10 />
  <a href="javascript:FindData()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
<div>
</body>
</html>

以下是取数据集,并将数据组装成json对象返回给前台的php代码
复制代码 代码如下:

<?php
include_once("auth.php");
include_once("inc/ms_conn.php");
include_once("inc/comm_function.php");
$PersonCode=$_POST["PersonCode"]; //前端传来的参数
$KQYM=$_POST["KQYM"];
$sqlstr="Exec dbo.HR_Prg_GetPersonYMKQ2 '$KQYM','$PersonCode'";
$rs =mssqlquery($sqlstr); //自定义的mssql方法,类拟mssql_query方法
$row = mssql_num_rows($rs); //取行总行数
$result["total"] = $row;
$items =array();
while ($row = mssql_fetch_array($rs)){
foreach($row as $key=>$value){
//这里很重要,php的json_encode只支持utf-8,否则含汉字字段值会被置为null
 $row[$key]=iconv('gb2312','UTF-8',$row[$key]); }
 array_push($items, $row); }
 $result["rows"] =$items;
 echo json_encode($result);
?>

以下为效果图

您可能感兴趣的文章:
Jquery easyui之控件参数传递方法
jQuery easyui datagrid动态查询数据实例讲解
EasyUI的treegrid组件动态加载数据问题的解决办法
jquery easyui datagrid合计行实例代码
Jquery easyui之datagird查询框扩展示例
Jquery下EasyUI组件中的DataGrid结果集清空方法
php使用EasyUI DataGrid获取资料的方式
基于datagrid框架的查询
jquery easyui利用DataGrid实现CRUD操作
jquery easyui开发几点总结

关键词: datagrid  动态查询   
[关闭]
~ ~