基本信息
源码名称:jQuery DataTables 与 ASP.NET MVC 集成
源码大小:0.12M
文件格式:.zip
开发语言:ASP
更新时间:2013-10-11
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
Part 2 - Implementation of CRUD functionalities (add, inline edit, delete) using DataTable in ASP.NET MVC where I have described how you can add data management (CRUD) functionalities such as adding, deleting and editing rows,
Part 3 - Reloading content of data tables in ASP.NET MVC where I have shown how you can reload DataTable content using Ajax,
Part 4 - Creating an expandable master-details table where I have shown how you can implement opening details row when regular row is selected,
Part 5 - jQuery DataTables Advanced Filtering in ASP.NET MVC - in this article is shown how you can implement advanced filtering,
Part 6 - Table Row Drag and Drop in ASP.NET MVC - in this article is descibed how you can use drag'n'drop row reordering.
jQuery DataTables 与 ASP.NET MVC 集成,Jquery Datable 插件是一款非常优秀的插件。在官网上没有提供C#实现,
这个实例来源于: http://www.codeproject.com/Articles/155422/jQuery-DataTables-and-ASP-NET-MVC-Integration-Part
这是一个系列,
如编辑,等高级功能参见:
:)感谢作者
。
$(document).ready(function () { var oTable = $('#myDataTable').dataTable({ "bServerSide": true, "sAjaxSource": "Home/AjaxHandler", "bProcessing": true, "aoColumns": [ { "sName": "ID", "bSearchable": false, "bSortable": false, "fnRender": function (oObj) { return '<a href=\"Company/Details/' oObj.aData[0] '\">View</a>'; } }, { "sName": "COMPANY_NAME" }, { "sName": "ADDRESS" }, { "sName": "TOWN" } ] }); });
public ActionResult AjaxHandler(JQueryDataTableParamModel param) { var allCompanies = DataRepository.GetCompanies(); IEnumerable<Company> filteredCompanies; //Check whether the companies should be filtered by keyword if (!string.IsNullOrEmpty(param.sSearch)) { //Used if particulare columns are filtered var nameFilter = Convert.ToString(Request["sSearch_1"]); var addressFilter = Convert.ToString(Request["sSearch_2"]); var townFilter = Convert.ToString(Request["sSearch_3"]); //Optionally check whether the columns are searchable at all var isNameSearchable = Convert.ToBoolean(Request["bSearchable_1"]); var isAddressSearchable = Convert.ToBoolean(Request["bSearchable_2"]); var isTownSearchable = Convert.ToBoolean(Request["bSearchable_3"]); filteredCompanies = DataRepository.GetCompanies() .Where(c => isNameSearchable && c.Name.ToLower().Contains(param.sSearch.ToLower()) || isAddressSearchable && c.Address.ToLower().Contains(param.sSearch.ToLower()) || isTownSearchable && c.Town.ToLower().Contains(param.sSearch.ToLower())); } else { filteredCompanies = allCompanies; } var isNameSortable = Convert.ToBoolean(Request["bSortable_1"]); var isAddressSortable = Convert.ToBoolean(Request["bSortable_2"]); var isTownSortable = Convert.ToBoolean(Request["bSortable_3"]); var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]); Func<Company, string> orderingFunction = (c => sortColumnIndex == 1 && isNameSortable ? c.Name : sortColumnIndex == 2 && isAddressSortable ? c.Address : sortColumnIndex == 3 && isTownSortable ? c.Town : ""); var sortDirection = Request["sSortDir_0"]; // asc or desc if (sortDirection == "asc") filteredCompanies = filteredCompanies.OrderBy(orderingFunction); else filteredCompanies = filteredCompanies.OrderByDescending(orderingFunction); var displayedCompanies = filteredCompanies.Skip(param.iDisplayStart).Take(param.iDisplayLength); var result = from c in displayedCompanies select new[] { Convert.ToString(c.ID), c.Name, c.Address, c.Town }; return Json(new { sEcho = param.sEcho, iTotalRecords = allCompanies.Count(), iTotalDisplayRecords = filteredCompanies.Count(), aaData = result }, JsonRequestBehavior.AllowGet); }