分享在MVC3.0中使用jQuery DataTable 插件
生活随笔
收集整理的這篇文章主要介紹了
分享在MVC3.0中使用jQuery DataTable 插件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
http://www.cnblogs.com/ryanding/archive/2011/02/18/1957318.html
官方網站
http://datatables.net/
HomeController public ActionResult GetJsonCitys(int? secho){var cityList = new List<Citys>();for (int i = 0; i < 100; i++){cityList.Add(new Citys{Id = i,CityName = Guid.NewGuid().ToString(),ZipCode = DateTime.Now.Millisecond});}var objs = new List<object>();foreach (var city in cityList){objs.Add(GetPropertyList(city).ToArray());}return Json(new{sEcho = secho,iTotalRecords = cityList.Count(),aaData = objs}, JsonRequestBehavior.AllowGet);}private List<string> GetPropertyList(object obj){var propertyList = new List<string>();var properties = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);foreach (var property in properties){object o = property.GetValue(obj, null);propertyList.Add(o == null ? "" : o.ToString());}return propertyList;}
?<span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);"><table?class="display"?id="DataTable"></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????<thead></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????<tr></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????<th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????????Id</span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????</th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????<th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????????CityName</span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????</th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????<th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????????ZipCode</span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????</th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????<th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????????操作</span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????</th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????</tr></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????</thead></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????<tbody></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????</tbody></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????</table></span><script type="text/javascript" charset="utf-8">$(document).ready(function () {$('#DataTable').dataTable({"oLanguage": {//語言國際化"sUrl": "/Scripts/Plug-in/jquery.dataTable.cn.txt"},"bJQueryUI": true,"sPaginationType": "full_numbers",'bPaginate': true, //是否分頁。"bProcessing": true, //當datatable獲取數據時候是否顯示正在處理提示信息。 "bServerSide": false,"sAjaxSource": "Home/GetJsonCitys","aoColumns": [{ "sTitle": "編號", "sClass": "center" },{ "sTitle": "城市名稱", "sClass": "center" },{ "sTitle": "郵政編碼", "sClass": "center" },{"sTitle": "操作","sClass": "center","fnRender": function (obj) {return '<a href=\"Details/' + obj.aData[0] + '\">查看詳情</a> <input tag=\"' + obj.aData[0] + '\" type=\"checkbox\" name=\"name\" />';}}]});});
MVC3.0中使用JQuery.DataTable插件
http://biancheng.dnbcw.info/net/350648.html
官方網站
http://datatables.net/
HomeController public ActionResult GetJsonCitys(int? secho){var cityList = new List<Citys>();for (int i = 0; i < 100; i++){cityList.Add(new Citys{Id = i,CityName = Guid.NewGuid().ToString(),ZipCode = DateTime.Now.Millisecond});}var objs = new List<object>();foreach (var city in cityList){objs.Add(GetPropertyList(city).ToArray());}return Json(new{sEcho = secho,iTotalRecords = cityList.Count(),aaData = objs}, JsonRequestBehavior.AllowGet);}private List<string> GetPropertyList(object obj){var propertyList = new List<string>();var properties = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);foreach (var property in properties){object o = property.GetValue(obj, null);propertyList.Add(o == null ? "" : o.ToString());}return propertyList;}
?<span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);"><table?class="display"?id="DataTable"></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????<thead></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????<tr></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????<th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????????Id</span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????</th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????<th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????????CityName</span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????</th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????<th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????????ZipCode</span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????</th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????<th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????????操作</span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????????</th></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????????</tr></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????</thead></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????<tbody></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????????</tbody></span><br style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);" /><span style="font-family: Simsun; font-size: 14px; line-height: 25px; background-color: rgb(244, 251, 244);">????</table></span><script type="text/javascript" charset="utf-8">$(document).ready(function () {$('#DataTable').dataTable({"oLanguage": {//語言國際化"sUrl": "/Scripts/Plug-in/jquery.dataTable.cn.txt"},"bJQueryUI": true,"sPaginationType": "full_numbers",'bPaginate': true, //是否分頁。"bProcessing": true, //當datatable獲取數據時候是否顯示正在處理提示信息。 "bServerSide": false,"sAjaxSource": "Home/GetJsonCitys","aoColumns": [{ "sTitle": "編號", "sClass": "center" },{ "sTitle": "城市名稱", "sClass": "center" },{ "sTitle": "郵政編碼", "sClass": "center" },{"sTitle": "操作","sClass": "center","fnRender": function (obj) {return '<a href=\"Details/' + obj.aData[0] + '\">查看詳情</a> <input tag=\"' + obj.aData[0] + '\" type=\"checkbox\" name=\"name\" />';}}]});});
轉載于:https://www.cnblogs.com/sui84/p/6777037.html
總結
以上是生活随笔為你收集整理的分享在MVC3.0中使用jQuery DataTable 插件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java nio的使用
- 下一篇: Service简介