jQuery easyui datagrid動態(tài)查詢數(shù)據(jù)實例講解
更新時間:2013年02月26日 16:02:27 作者:
接下來將從前臺提交查詢條件,從MSSQL返回json數(shù)據(jù)的一個事例來講解一下datagrid動態(tài)查詢數(shù)據(jù),感興趣的你可不要錯過了哈,希望本文可以幫助到你
該插件組小巧使用方便,以下是一個從前臺提交查詢條件,從MSSQL返回json數(shù)據(jù)的一個事例
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>
以下是取數(shù)據(jù)集,并將數(shù)據(jù)組裝成json對象返回給前臺的php代碼
<?php
include_once("auth.php");
include_once("inc/ms_conn.php");
include_once("inc/comm_function.php");
$PersonCode=$_POST["PersonCode"]; //前端傳來的參數(shù)
$KQYM=$_POST["KQYM"];
$sqlstr="Exec dbo.HR_Prg_GetPersonYMKQ2 '$KQYM','$PersonCode'";
$rs =mssqlquery($sqlstr); //自定義的mssql方法,類擬mssql_query方法
$row = mssql_num_rows($rs); //取行總行數(shù)
$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);
?>
以下為效果圖
HTML前端代碼
復(fù)制代碼 代碼如下:
<?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>
以下是取數(shù)據(jù)集,并將數(shù)據(jù)組裝成json對象返回給前臺的php代碼
復(fù)制代碼 代碼如下:
<?php
include_once("auth.php");
include_once("inc/ms_conn.php");
include_once("inc/comm_function.php");
$PersonCode=$_POST["PersonCode"]; //前端傳來的參數(shù)
$KQYM=$_POST["KQYM"];
$sqlstr="Exec dbo.HR_Prg_GetPersonYMKQ2 '$KQYM','$PersonCode'";
$rs =mssqlquery($sqlstr); //自定義的mssql方法,類擬mssql_query方法
$row = mssql_num_rows($rs); //取行總行數(shù)
$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 API 中文文檔 - DataGrid數(shù)據(jù)表格
- Jquery下EasyUI組件中的DataGrid結(jié)果集清空方法
- 擴展easyui.datagrid,添加數(shù)據(jù)loading遮罩效果代碼
- jQuery EasyUI datagrid實現(xiàn)本地分頁的方法
- jQuery EasyUI之DataGrid使用實例詳解
- jQuery Easyui DataGrid點擊某個單元格即進(jìn)入編輯狀態(tài)焦點移開后保存數(shù)據(jù)
- 實現(xiàn)easyui的datagrid導(dǎo)出為excel的示例代碼
- 詳解EasyUi控件中的Datagrid
- jquery Easyui Datagrid實現(xiàn)批量操作(編輯,刪除,添加)
- EasyUI使用DataGrid實現(xiàn)動態(tài)列數(shù)據(jù)綁定
相關(guān)文章
jquery表單驗證插件(jquery.validate.js)的3種使用方式
這篇文章主要介紹了jquery表單驗證插件(jquery.validate.js)的3種使用方式,本文用詳細(xì)的代碼實例講解jquery表單驗證插件的使用,需要的朋友可以參考下2015-03-03jquery實現(xiàn)走馬燈特效實例(撲克牌切換效果)
本文主要介紹了jquery實現(xiàn)走馬燈特效實例(撲克牌切換效果),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02