The previous chapter describes the basic usage of DataTables, link address: http://www.cnblogs.com/wumian1360/p/4263129.html
Today to achieve 5,6,7 three points.
In fact, the DataTables control itself has a paging property, sorting properties and Filter properties, namely: Bpaginate,bsort,bfilter, we only need to set these three properties to true, then the Ajax refresh in the query String The parameters has parameters. Specific as follows:
1Secho:1//the number of operations, the specific use is not very clear2Icolumns:2//DataTables Total number of columns3Scolumns:id,name//Column Name4idisplaystart:0//Pagination Start Page5Idisplaylength:10//number of rows displayed per page6Mdataprop_0:id//first column mapping field7SSEARCH_0://first column filter content8BREGEX_0:false //whether the field uses regular9Bsearchable_0:true //whether to use the filter featureTenBsortable_0:false //Whether you can sort OneMdataprop_1:name//first column mapping field ASsearch_1://first column filter content -Bregex_1:false //whether the field uses regular -Bsearchable_1:true //whether to use the filter feature theBsortable_1:true //Whether you can sort -Ssearch://full-text filtering -Bregex:false //whether to use the regular -isortcol_0:0//index of the current row sequence (first column) +Ssortdir_0:asc//sort to ascending -Isortingcols:1//number of columns sorted +_:1423311150960
HTTP Request Parameters
The function is very powerful ah, everything has, then only need to create objects to accept processing these parameters, and then use the object to separate pagination, sorting and filtering can be.
The processing object class uses the "Champion" Code, specific link: http://www.cnblogs.com/haogj/archive/2011/03/21/1990595.html
With this object, it can be handled in a specific controller.
The code is as follows:
1 Public Jsonresult Get ()2 {3Datatablesrequest Parm =NewDatatablesrequest ( This. Request);//Working with Objects4 intTotalCount = 0; 5 intstart = Parm.idisplaystart;//Page Index6 intlength = Parm.idisplaylength;//number of page lines7String order = string. Empty;//Sort8 9 //Get SortTen if(Parm. Sortcolumns.count () > 0) One { AString SortField = Parm. Columns[parm. Sortcolumns[0]. Index]. Name; -String sort = parm. Sortcolumns[0]. Direction.tostring (); -Order = SortField + "" +sort; the } - -String strquery =Parm. Search; -string[] Fields =NewString[parm.icolumns]; + //Here you can create objects to encapsulate the contents of a full-text query field, simple, personal to implement - + varlist=XXXX. LoadPage (start,length,out totalcount,order,strquery,fields) A at returnJson (New{aadata = list, itotalrecords = totalcount, itotaldisplayrecords =TotalCount}, - jsonrequestbehavior.allowget); -}Ctroller Operation
JQuery Datatables (ii)