基于datagrid框架的查詢
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="jquery-easyui-1.3.2/themes/default/easyui.css" rel="stylesheet" />
<link href="jquery-easyui-1.3.2/themes/icon.css" rel="stylesheet" />
<script src="jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>
<script src="JavaScript.js"></script><!--這個(gè)是擴(kuò)展Jquery的方法-->
<script src="jquery-easyui-1.3.2/jquery.easyui.min.js"></script>
<script src="jquery-easyui-1.3.2/locale/easyui-lang-zh_CN.js"></script>
</head>
<body id="layoutbody" class="easyui-layout">
<div data-options="region:'north',title:'North Title',split:true" style="height: 100px;">
</div>
<div data-options="region:'south',title:'South Title',split:true" style="height: 100px;">
</div>
<div data-options="region:'east',iconCls:'icon-reload',title:'East',split:true" style="width: 100px;">
</div>
<div data-options="region:'west',title:'West',split:true" style="width: 100px;">
</div>
<div data-options="region:'center',title:'center title'" href="CenterPage.html" style="background: #eee; overflow: hidden;">
</div>
</body>
然后是CenterPage.html框架中的代碼,也就是tabs框架中的代碼:
<script type="text/javascript" charst="utf-8">
//因?yàn)閘ayout框架指向href時(shí),只取html頁面body中間的部分,所以該頁面這樣寫即可
//有datagrid包含屬性較多,所以盡量使用js的方式初始化datagrid框架
$(function () {
$("#dg").datagrid({
url: "GetJson.ashx", //指向一個(gè)一般處理程序或者一個(gè)控制器,返回?cái)?shù)據(jù)要求是Json格式,直接賦值Json格式數(shù)據(jù)也可,我以demo中自帶的Json數(shù)據(jù)為例,就不寫后臺(tái)代碼了,但是我會(huì)說下后臺(tái)返回的注意事項(xiàng)
iconCls: "icon-add",
fitColumns: false, //設(shè)置為true將自動(dòng)使列適應(yīng)表格寬度以防止出現(xiàn)水平滾動(dòng),false則自動(dòng)匹配大小
//toolbar設(shè)置表格頂部的工具欄,以數(shù)組形式設(shè)置
idField: 'id', //標(biāo)識(shí)列,一般設(shè)為id,可能會(huì)區(qū)分大小寫,大家注意一下
loadMsg: "正在努力為您加載數(shù)據(jù)", //加載數(shù)據(jù)時(shí)向用戶展示的語句
pagination: true, //顯示最下端的分頁工具欄
rownumbers: true, //顯示行數(shù) 1,2,3,4...
pageSize: 10, //讀取分頁條數(shù),即向后臺(tái)讀取數(shù)據(jù)時(shí)傳過去的值
pageList: [10, 20, 30], //可以調(diào)整每頁顯示的數(shù)據(jù),即調(diào)整pageSize每次向后臺(tái)請求數(shù)據(jù)時(shí)的數(shù)據(jù)
//由于datagrid的屬性過多,我就不每個(gè)都介紹了,如有需要,可以看它的API
sortName: "name", //初始化表格時(shí)依據(jù)的排序 字段 必須和數(shù)據(jù)庫中的字段名稱相同
sortOrder: "asc", //正序
columns: [[
{ field: 'code', title: 'Code', width: 100 },
{ field: 'name', title: 'Name', width: 100, sortable: true },//sortable:true點(diǎn)擊該列的時(shí)候可以改變升降序
{ field: 'addr', title: 'addr', width: 100 }
]],//這里之所以有兩個(gè)方括號(hào),是因?yàn)榭梢宰龀伤?bào)表形式,具體可看demo
toolbar: [{//在dategrid表單的頭部添加按鈕
text: "添加",
iconCls: "icon-add",
handler: function () {
}
}, '-', {//'-'就是在兩個(gè)按鈕的中間加一個(gè)豎線分割,看著舒服
text: "刪除",
iconCls: "icon-remove",
handler: function () {
}
}, '-', {
text: "修改",
iconCls: "icon-edit",
handler: function () {
}
}, '-']
});
});
//點(diǎn)擊查找按鈕出發(fā)事件
function searchFunc() {
alert("123");
$("#dg").datagrid("load", sy.serializeObject($("#searchForm").form()));//將searchForm表單內(nèi)的元素序列為對(duì)象傳遞到后臺(tái)
}
//點(diǎn)擊清空按鈕出發(fā)事件
function clearSearch() {
$("#dg").datagrid("load", {});//重新加載數(shù)據(jù),無填寫數(shù)據(jù),向后臺(tái)傳遞值則為空
$("#searchForm").find("input").val("");//找到form表單下的所有input標(biāo)簽并清空
}
</script>
<div class="easyui-tabs" fit="true" border="false">
<div title="數(shù)據(jù)展示表格" border="false" fit="true">
<div class="easyui-layout" fit="true" border="false">
<!--由于查詢需要輸入條件,但是以toolbar的形式不好,所以我們在Layout框架的頭部north中書寫查詢的相關(guān)信息-->
<!-- 這里我們盡量使其展示的樣式與toolbar的樣式相似,所以我們先查找toolbar的樣式,并復(fù)制過來-->
<div data-options="region:'north',title:'高級(jí)查詢'" style="height: 100px; background: #F4F4F4;">
<form id="searchForm">
<table>
<tr>
<th>用戶姓名:</th>
<td>
<input name="name" /></td>
</tr>
<tr>
<th>創(chuàng)建開始時(shí)間</th>
<td>
<input class="easyui-datetimebox" editable="false" name="subStartTime" /></td>
<!--由于datebox框架上面的數(shù)據(jù)必須是時(shí)間格式的,所以我們用editable="false"來禁止用戶手動(dòng)輸入,以免報(bào)錯(cuò)-->
<th>創(chuàng)建結(jié)束時(shí)間</th>
<td>
<input class="easyui-datetimebox" editable="false" name="nsubEndTimeame" /></td>
<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="searchFunc();">查找</a></td>
<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="clearSearch();">清空</a></td>
</tr>
</table>
</form>
</div>
<div data-options="region:'center',split:false">
<table id="dg">
</table>
</div>
</div>
</div>
</div>
Jquery的擴(kuò)展代碼:
var sy = $.extend({}, sy);/*定義一個(gè)全局變量*/
sy.serializeObject = function (form) { /*將form表單內(nèi)的元素序列化為對(duì)象,擴(kuò)展Jquery的一個(gè)方法*/
var o = {};
$.each(form.serializeArray(), function (index) {
if (o[this['name']]) {
o[this['name']] = o[this['name']] + "," + this['value'];
} else {
o[this['name']] = this['value'];
}
});
return o;
};
圖示:

相關(guān)文章
jQuery簡單創(chuàng)建節(jié)點(diǎn)的方法
這篇文章主要介紹了jQuery簡單創(chuàng)建節(jié)點(diǎn)的方法,涉及jQuery獲取節(jié)點(diǎn)及append添加元素創(chuàng)建節(jié)點(diǎn)的相關(guān)技巧,需要的朋友可以參考下2016-09-09
jQuery實(shí)現(xiàn)類似淘寶網(wǎng)圖片放大效果的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)類似淘寶網(wǎng)圖片放大效果的方法,實(shí)例分析了jquery實(shí)現(xiàn)圖片放大效果的方法,涉及jquery操作鼠標(biāo)事件及頁面元素屬性修改的相關(guān)技巧,需要的朋友可以參考下2015-07-07
Jquery 設(shè)置標(biāo)題的自動(dòng)翻轉(zhuǎn)
我們平時(shí)在開發(fā)web程序的時(shí)候,想把一個(gè)新聞源滾動(dòng)顯示新聞的條目的標(biāo)題及內(nèi)容摘要,而且是每次一條,有點(diǎn)類似csdn的滾動(dòng)廣告。2009-10-10
jQuery使用ajax傳遞json對(duì)象到服務(wù)端及contentType的用法示例
這篇文章主要介紹了jQuery使用ajax傳遞json對(duì)象到服務(wù)端及contentType的用法,結(jié)合實(shí)例形式分析了jQuery使用ajax傳遞json對(duì)象數(shù)據(jù)及服務(wù)器響應(yīng)相關(guān)操作技巧,需要的朋友可以參考下2020-03-03
基于jquery & json的省市區(qū)聯(lián)動(dòng)代碼
基于jquery & json的省市區(qū)聯(lián)動(dòng)代碼,需要的朋友可以參考下2012-06-06
jquery實(shí)現(xiàn)兼容瀏覽器的圖片上傳本地預(yù)覽功能
圖片上傳本地預(yù)覽功能代碼在網(wǎng)上可以搜索很多,但同時(shí)可以兼容瀏覽器的話就多了,本文有個(gè)不錯(cuò)的示例,感興趣的朋友可以參考下2013-10-10
jQuery實(shí)現(xiàn)的網(wǎng)站banner圖片無縫輪播效果完整實(shí)例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的網(wǎng)站banner圖片無縫輪播效果,結(jié)合完整實(shí)例形式分析了jQuery結(jié)合時(shí)間函數(shù)實(shí)現(xiàn)圖片定時(shí)輪播切換相關(guān)操作技巧,需要的朋友可以參考下2019-01-01
整理8個(gè)很棒的 jQuery 倒計(jì)時(shí)插件和教程
jQuery 是最流行也是使用最廣泛的 JavaScript 框架,它簡化了 HTML 文檔操作,事件處理,動(dòng)畫效果和 Ajax 交互。下面向大家分享8個(gè)優(yōu)秀的 jQuery 倒計(jì)時(shí)插件和教程2011-12-12

