jQuery easyui datagrid動(dòng)態(tài)查詢數(shù)據(jù)實(shí)例講解
更新時(shí)間:2013年02月26日 16:02:27 作者:
接下來(lái)將從前臺(tái)提交查詢條件,從MSSQL返回json數(shù)據(jù)的一個(gè)事例來(lái)講解一下datagrid動(dòng)態(tài)查詢數(shù)據(jù),感興趣的你可不要錯(cuò)過了哈,希望本文可以幫助到你
該插件組小巧使用方便,以下是一個(gè)從前臺(tái)提交查詢條件,從MSSQL返回json數(shù)據(jù)的一個(gè)事例
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="請(qǐng)輸入查詢條件"
rownumbers="true" toolbar="#searchtool" loadMsg="正在查詢...">
<thead>
<tr>
<th field="PersonCode" Width="80">工號(hào)</th>
<th field="MyName" width="80">姓名</th>
<th field="KQDate" width="100">考勤日期</th>
<th field="MyWeek" width="80">星期</th>
<th field="KQMemo" width="200">打卡時(shí)間</th>
</tr>
</thead>
</table>
<div id="searchtool" style="padding:5px">
<span>工號(hào):</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對(duì)象返回給前臺(tái)的php代碼
<?php
include_once("auth.php");
include_once("inc/ms_conn.php");
include_once("inc/comm_function.php");
$PersonCode=$_POST["PersonCode"]; //前端傳來(lái)的參數(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,否則含漢字字段值會(huì)被置為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="請(qǐng)輸入查詢條件"
rownumbers="true" toolbar="#searchtool" loadMsg="正在查詢...">
<thead>
<tr>
<th field="PersonCode" Width="80">工號(hào)</th>
<th field="MyName" width="80">姓名</th>
<th field="KQDate" width="100">考勤日期</th>
<th field="MyWeek" width="80">星期</th>
<th field="KQMemo" width="200">打卡時(shí)間</th>
</tr>
</thead>
</table>
<div id="searchtool" style="padding:5px">
<span>工號(hào):</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對(duì)象返回給前臺(tái)的php代碼
復(fù)制代碼 代碼如下:
<?php
include_once("auth.php");
include_once("inc/ms_conn.php");
include_once("inc/comm_function.php");
$PersonCode=$_POST["PersonCode"]; //前端傳來(lái)的參數(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,否則含漢字字段值會(huì)被置為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é)果集清空方法
- 擴(kuò)展easyui.datagrid,添加數(shù)據(jù)loading遮罩效果代碼
- jQuery EasyUI datagrid實(shí)現(xiàn)本地分頁(yè)的方法
- jQuery EasyUI之DataGrid使用實(shí)例詳解
- jQuery Easyui DataGrid點(diǎn)擊某個(gè)單元格即進(jìn)入編輯狀態(tài)焦點(diǎn)移開后保存數(shù)據(jù)
- 實(shí)現(xiàn)easyui的datagrid導(dǎo)出為excel的示例代碼
- 詳解EasyUi控件中的Datagrid
- jquery Easyui Datagrid實(shí)現(xiàn)批量操作(編輯,刪除,添加)
- EasyUI使用DataGrid實(shí)現(xiàn)動(dòng)態(tài)列數(shù)據(jù)綁定
相關(guān)文章
jquery表單驗(yàn)證插件(jquery.validate.js)的3種使用方式
這篇文章主要介紹了jquery表單驗(yàn)證插件(jquery.validate.js)的3種使用方式,本文用詳細(xì)的代碼實(shí)例講解jquery表單驗(yàn)證插件的使用,需要的朋友可以參考下2015-03-03基于jquery的滾動(dòng)鼠標(biāo)放大縮小圖片效果
基于jquery的滾動(dòng)鼠標(biāo)放大縮小圖片效果,需要的朋友可以參考下。2011-10-10用jQuery實(shí)現(xiàn)圓點(diǎn)圖片輪播效果
在頁(yè)面的指定位置實(shí)現(xiàn)的圖片自動(dòng)的左右輪流切換展示效果,當(dāng)點(diǎn)擊圖片左下的標(biāo)簽(或中間的小圓點(diǎn))切換到對(duì)應(yīng)的圖片。接下來(lái)通過本文給大家分享用jQuery實(shí)現(xiàn)圓點(diǎn)圖片輪播效果實(shí)例代碼,需要的朋友參考下2017-03-03jquery 判斷滾動(dòng)條到達(dá)了底部和頂端的方法
這篇文章主要介紹了jquery 判斷滾動(dòng)條到達(dá)了底部和到達(dá)頂端的方法,需要的朋友可以參考下2014-04-04jQuery窗口拖動(dòng)功能的實(shí)現(xiàn)代碼
本文通過jquery代碼實(shí)現(xiàn)窗口拖動(dòng)功能以及jQuery 鼠標(biāo)拖拽移動(dòng)窗口的實(shí)現(xiàn)代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下2017-02-02jquery實(shí)現(xiàn)走馬燈特效實(shí)例(撲克牌切換效果)
本文主要介紹了jquery實(shí)現(xiàn)走馬燈特效實(shí)例(撲克牌切換效果),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02