分享在MVC3.0中使用jQuery DataTable 插件
http://www.cnblogs.com/ryanding/archive/2011/02/18/1957318.html
官方网站
http://datatables.net/
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\" />'; } } ] }); });
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!