亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JQueryEasyUI datagrid框架的基本使用

 更新時間:2013年04月08日 10:31:26   作者:  
本篇文章小編為大家介紹一下JQueryEasyUI datagrid框架的基本使用,有需要的朋友可以參考一下本文。

今天說說這個datagrid框架的基本使用,這個框架一直以來都是大家比較頭疼的框架,尤其是Json數(shù)據(jù)的拼接,后臺前臺都很重要,使用這個框架,最重要的是仔細(xì):
無需廢話,上代碼了:

復(fù)制代碼 代碼如下:

<link href="jquery-easyui-1.3.2/themes/default/easyui.css" rel="stylesheet" type="text/css" />
<!--easyui最全的樣式包也可單獨引用你想使用的樣式包-->
<link href="jquery-easyui-1.3.2/themes/icon.css" rel="stylesheet" type="text/css" />
<!--easyui自帶圖片樣式包,也可自行添加-->
<script src="jquery-easyui-1.3.2/jquery-1.8.0.min.js" type="text/javascript"></script>
<!--我使用的是easyui 1.3.2,基于jquery-1.8.0-->
<script src="jquery-easyui-1.3.2/jquery.easyui.min.js" type="text/javascript"></script>
<!--easyui的js包-->
<script src="jquery-easyui-1.3.2/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<!--easyui的中文語言包,默認(rèn)是英文-->
</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="HTMLPage.htm" style="padding: 5px;
background: #eee; overflow: hidden;"><!--這里指向了一個htm頁-->
</div>
</body>
</html>

HTMLPage.htm代碼:
復(fù)制代碼 代碼如下:

<script type="text/javascript" charst="utf-8">
//因為layout框架指向href時,只取html頁面body中間的部分,所以該頁面這樣寫即可
//有datagrid包含屬性較多,所以盡量使用js的方式初始化datagrid框架
$(function () {
$("#dg").datagrid({
url: "GetJson.ashx", //指向一個一般處理程序或者一個控制器,返回數(shù)據(jù)要求是Json格式,直接賦值Json格式數(shù)據(jù)也可,我以demo中自帶的Json數(shù)據(jù)為例,就不寫后臺代碼了,但是我會說下后臺返回的注意事項
title: "數(shù)據(jù)展示表格",
iconCls: "icon-add",
fitColumns: false, //設(shè)置為true將自動使列適應(yīng)表格寬度以防止出現(xiàn)水平滾動,false則自動匹配大小
//toolbar設(shè)置表格頂部的工具欄,以數(shù)組形式設(shè)置
idField: 'id', //標(biāo)識列,一般設(shè)為id,可能會區(qū)分大小寫,大家注意一下
loadMsg: "正在努力為您加載數(shù)據(jù)", //加載數(shù)據(jù)時向用戶展示的語句
pagination: true, //顯示最下端的分頁工具欄
rownumbers: true, //顯示行數(shù) 1,2,3,4...
pageSize: 10, //讀取分頁條數(shù),即向后臺讀取數(shù)據(jù)時傳過去的值
pageList: [10, 20, 30], //可以調(diào)整每頁顯示的數(shù)據(jù),即調(diào)整pageSize每次向后臺請求數(shù)據(jù)時的數(shù)據(jù)
//由于datagrid的屬性過多,我就不每個都介紹了,如有需要,可以看它的API
sortName: "name", //初始化表格時依據(jù)的排序 字段 必須和數(shù)據(jù)庫中的字段名稱相同
sortOrder: "asc", //正序
columns: [[
{ field: 'code', title: 'Code', width: 100 },
{ field: 'name', title: 'Name', width: 100 ,sortable:true},//sortable:true點擊該列的時候可以改變升降序
{ field: 'addr', title: 'addr', width: 100,
//這里可以添加這樣一個方法,使其顯示數(shù)據(jù)得到改變
// formatter: function (value, row, index) {
// if (value == "0") {
// return "普通角色";
// } else {
// return "特殊角色";
// }
// }
}
]]//這里之所以有兩個方括號,是因為可以做成水晶報表形式,具體可看demo
});
});
</script>
<div id="tt" class="easyui-tabs" style="width: 500px; height: 250px;" fit="true"
border="false">
<div title="Tab1" style="padding: 20px;" border="false">
<table id="dg">
</table>
</div>
</div>

這是前臺請求數(shù)據(jù)時發(fā)送的數(shù)據(jù);

Json格式數(shù)據(jù)一定要是雙引號的,單引號無法顯示數(shù)據(jù)哦;

數(shù)據(jù)格式如下:

復(fù)制代碼 代碼如下:

{
"total":239,
"rows":[
{"code":"001","name":"Name 1","addr":"Address 11","col4":"col4 data"},
{"code":"002","name":"Name 2","addr":"Address 13","col4":"col4 data"},
{"code":"003","name":"Name 3","addr":"Address 87","col4":"col4 data"},
{"code":"004","name":"Name 4","addr":"Address 63","col4":"col4 data"},
{"code":"005","name":"Name 5","addr":"Address 45","col4":"col4 data"},
{"code":"006","name":"Name 6","addr":"Address 16","col4":"col4 data"},
{"code":"007","name":"Name 7","addr":"Address 27","col4":"col4 data"},
{"code":"008","name":"Name 8","addr":"Address 81","col4":"col4 data"},
{"code":"009","name":"Name 9","addr":"Address 69","col4":"col4 data"},
{"code":"010","name":"Name 10","addr":"Address 78","col4":"col4 data"}
]
}

這里呢,后臺傳遞數(shù)據(jù)很重要:

注意:表格Post或者get回來的請求中
page:3 代表page為key,然后選擇的當(dāng)前頁碼為3
rows:10 代表一頁的大小為10
后臺返回的數(shù)據(jù)的格式為:{total:'',rows:[{},{}]}
只要包含了總數(shù)tatol字段,rows是具體的行數(shù)
例如:
Asp.Net MVC 例子:
public JsonResult GetAllUserInfos()
{
int pageSize = 5;
int pageIndex = 1;
int.TryParse(this.Request["page"], out pageIndex);
int.TryParse(this.Request["rows"], out pageSize);

pageSize = pageSize <= 0 ? 5 : pageSize;
pageIndex = pageIndex < 1 ? 1 : pageIndex;

var temp = db.UserInfo
.OrderBy(u=>u.Sort)
.Skip<UserInfo>((pageIndex-1)*pageSize)
.Take<UserInfo>(pageSize)
.ToList<UserInfo>();
Hashtable ht = new Hashtable();
ht["total"] = db.UserInfo.Count();
ht["rows"] = temp;
return Json(ht);
}

Asp.Net WebForm 例子:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
var strWebName = context.Request["WebName"] ?? string.Empty;
var GoodsNo = context.Request["GoodsNo"] ?? string.Empty;
int categoryId = 0;

int pageIndex = 1;
int pageSize = 10;

int.TryParse(context.Request["rows"], out pageSize);
int.TryParse(context.Request["page"], out pageIndex);

decimal priceLeft = 0;
decimal priceRight = 1000000;
int goodsStatus = 0;
decimal.TryParse(context.Request["PriceLeft"], out priceLeft);
decimal.TryParse(context.Request["PriceRight"], out priceRight);
int.TryParse(context.Request["CategoryId"], out categoryId);
int.TryParse(context.Request["GoodsStatus"], out goodsStatus);
var goodsQueryParamter = new GoodsQueryParamter();


goodsQueryParamter.GoodsStatus = (Model.GoodsModel.GoodsStatusEnum)goodsStatus;

var ds = goodsService.GetGoodsList(goodsQueryParamter);
string json = string.Empty;

if (ds != null && ds.Tables.Count > 0)
{
System.Text.StringBuilder rowJson = new System.Text.StringBuilder();
int colLen = ds.Tables[0].Columns.Count;
DataColumnCollection col = ds.Tables[0].Columns;
foreach (DataRow row in ds.Tables[0].Rows)
{
System.Text.StringBuilder colJson = new System.Text.StringBuilder();
rowJson.Append("{");
for (int i = 0; i < colLen; i++)
{
colJson.Append("\"" + col[i].ColumnName + "\":\"" + row[i].ToString() + "\",");
}
rowJson.Append(colJson.ToString().TrimEnd(','));
rowJson.Append("},");
}
json = "{\"total\":" + ds.Tables[0].Rows[0]["sumGoods"] + ",\"rows\":[" + rowJson.ToString().TrimEnd(',') + "]}";
}
context.Response.Write(json);
}

ASP.Net中有一個類也可以序列化Json格式數(shù)據(jù);

相關(guān)文章

最新評論