recently in the function of paging query, in the Internet also looked at a lot, but their absorption ability is a lot worse, and then the biggest idea is, how there is no I want the kind, both easyui and use mvc The architecture, but also to achieve the underlying paging value, with .net platform written demo At that time, I thought, when I did it, I also want to write a paged query blog, specifically to achieve this need to do the demo
Front deskView
<table id= "List_data" class= "Easyui-datagrid" style= "width:1075px;height:300px" cellpascing= "0" cellpadding= "0" ></table>
<script type= "Text/javascript" >//Table Style $ (function () {$ (' #list_data '). Datagr ID ({title: ' Suggested ', Iconcls: ' Icon-view ',//icon LOADMSG: "Data loading, please later ...", width:1056, height: ' Au To ', Nowrap:false, Striped:true, Border:true, Collapsible:false,//Can be folded fit:true,//automatic size URL: "/evaluationsuggestion/getdata",//controller address, Controller's name + method of returning JSON Remotesort:false, Singleselect:true,//whether radio Pag Ination:true,//pagination control Rownumbers:false,//Line number Columns[[{field: ' Suggestioncontent ', title: ' Suggested ', Width: ' 1056 '},//Select ]], }); Set the paging control var p=$ (' #list_data '). DataGrid (' Getpager '); $ (P). Pagination ({pagenumber:1,//Show page number Pagesize:10 by default, PAGELIST:[5,10,15], Beforepagetext: ' First ', Afterpagetext: ' page total {pages} page ', displaymsg: ' Current display {from}-{to} record ' {total} ' record ' }); }); </script>
Explanation: If you want to make pagination, you must first DataGrid of the Properties pagination set to true .
Pager is the page bar, which is used to set the paging's overall parameters,
URL is the important root address of the link, Pager The tab will append the paging parameters to this link.
Controller.cs
#region Query the proposed controller///<summary>//////</summary>///< ;returns> return value action for interacting with the view layer </returns> public ActionResult Suggestionindex () { return View (); #endregion #region Convert the proposed data to a JSON string///<summary>///Convert the proposed data to a JSON string///</S ummary>//<returns> return JSON string </returns> public Jsonresult GetData () {IEv ALUATIONSUGGESTIONWCF suggestion = Servicefactory.getevaluationsuggestion (); list<evaluationsuggestion> Lstresut = new list<evaluationsuggestion> (); Receive the parameter var pageIndex = int from the DataGrid. Parse (request["page"]); Current page var pageSize = Int. Parse (request["Rows"]); Page line var total = 0; Lstresut = suggestion. Querysuggestionbypage (PageSize, PageIndex, out total); var data = new { Total, rows = Lstresut}; return Json (data, jsonrequestbehavior.allowget); } #endregion
Explanation: page and the rows can be obtained directly from the front desk. data format, converted to a Json string, can be correctly retrieved in the paging.
Service side
#region Page Search + Sort by:///<summary>/////</summary>///<typeparam NA Me= "Tkey" > Generics </typeparam>//<param name= "pageSize" > per page size </param>//<param name= "PA Geindex "> Current page number </param>//<param name=" Total "> Overall quantity </param>//<param name=" Orderbyla MBDA "> Sorting criteria </param>//<param name=" ISASC "> whether ascending </param>//<returns>iqueryable pan Type collection </returns> public iqueryable<t> loadpageitems<tkey> (int pageSize, int. PageIndex, out int total , Func<t, tkey> Orderbylambda, bool isasc) {total = Mybasedbcontext.set<t> (). Count (); if (ISASC) {var temp = mybasedbcontext.set<t> (). Orderby<t, Tkey> (ORDERBYLAMBDA). Skip (PageSize * (pageIndex-1)). Take (pageSize); Return temp. AsqueryabLe (); } else {var temp = mybasedbcontext.set<t> (). Orderbydescending<t, Tkey> (ORDERBYLAMBDA). Skip (PageSize * (pageIndex-1)). Take (pageSize); Return temp. AsQueryable (); }} #endregion
Explanation: This is our bottom class library, I directly posted, the bottom of the use EF , involving Lambda an expression. Except the form, the idea of paged query is the same, true paging, based on the total number of records, the number of records per page and the current page number, get the current page number of data collection. Number of pages = Total records / pages per page. Data collection for the current page number, passing conditional filtering to the database, from(Current page -1)* number of records per page to Current page number * number of records per page Gets the current page Number data collection. Do it for yourself.
(Easyui datagrid+mvc+json) ASP. NET Paging Query