- ASP. NET MVC build Project Background UI Framework-1, background main frame
- ASP. NET MVC build Project Background UI Framework-2, menu effects
- ASP. NET MVC build Project Background UI Framework-3, panel folding and unwinding
- ASP. NET MVC build Project Background UI Framework-4, TAB multi-page support
- ASP. NET MVC build Project Background UI Framework-5, demo demo Controller and view interaction
- ASP. NET MVC build Project Background UI Framework-6, customer management (add, modify, query, paging)
- ASP. NET MVC build Project Background UI Framework-7, statistical report
- ASP. NET MVC build a project background UI framework-8. Pass some data from the selected data row in the view into the controller
- ASP. NET MVC build Project Background UI Framework-9, server-side sort
On the server-side sort of jquery datables, it seems like you haven't seen it online. NET example, to tell the truth, before I also confused, accustomed to directly from the Internet to find ready-made things, after a search, did not find, as a result, their own debugging Bai, adjusted the front desk, the background, and really I saw the law. In fact, Datables is a multi-column sort, but in this case, I've only written a single column.
In the controller,
dictionary<int,string> Dicsort =Newdictionary<int,string> ();//sort field Key-value pairs list (column ordinal, column name) /// <summary> ///waybill Exception Data/// </summary> /// <returns></returns> PublicActionResult Waybillexception (waybillexceptionfilter filter) {returnView (filter); } PublicJsonresult Waybillexceptionlist (waybillexceptionfilter filter) {Dicsort.add (2,"W.postingtime"); Datatablesrequest Parm=NewDatatablesrequest ( This. Request);//Working with Objects intPageIndex = Parm.idisplaylength = =0?0: Parm.idisplaystart/parm.idisplaylength; Filter. PageIndex= PageIndex;//Page IndexFilter. PageSize = Parm.idisplaylength;//number of page lines stringStrsortfield = dicsort.where (x = = X.key = = Parm. sortcolumns[0]. Index). Select (x =x.value). FirstOrDefault (); stringStrsortdire = Parm. sortcolumns[0]. Direction = = Sortdirection.asc?"ASC":"desc"; Filter. by=" "+ Strsortfield +" "+Strsortdire; varDataSource = Core.Reconciliation.WayBillException.GetByFilter (filter) asWrpageoflist<waybillexception>; inti = parm.idisplaylength *PageIndex; List<WayBillException> Querydata =datasource.tolist (); vardata = querydata.select (U =New{Index= ++i,//Line numberID =u.id, Isinputcost=U.isinputcost, Cusname= U.cusname,//customer abbreviationPostingtime = U.postingtime = =NULL?string. Empty:u.postingtime.value.tostringdate (),//date of receipt of shipmentExpressno = U.expressno,//waybill numberBatchno = U.loadbillnum,//Bill of lading numberWeight = U.weight = =NULL? 0m:u.weight/ +,//WeightWaybillfee = U.waybillfee,//postageProcessingfee = U.processingfee,//postal mail processing feeIncomewaybillfee = U.expressfee,//Customer FreightIncomeopratefee = U.operatefee,//Customer operation FeeWaybillmargins = U.waybillprofit,//Freight Gross marginTotalmargins = U.expressfee + U.operatefee + u.incomeotherfee-(U.waybillfee + U.processingfee + u.CostOtherFee),//Gross marginMargin = Math.Round ((u.expressfee + u.operatefee + U.incomeotherfee = =0? 0m: (U.expressfee + u.operatefee + u.incomeotherfee-
(U.waybillfee + U.processingfee + u.costotherfee)) /(U.expressfee + u.operatefee + u.incomeotherfee) * -),2) +"%",
//Gross margin gross margin = (gross income-total cost of expenditure)/total revenue *100%Reconciledate = U.reconciledate.tostringdate (),//Reconciliation DateCostotherfee = U.costotherfee,//cost Other costsCosttotalfee = U.waybillfee + U.processingfee + u.costotherfee,//Total cost costsCoststatus = U.coststatus.tochinese (),//Cost StatusIncomeotherfee = U.incomeotherfee,//Income Other ExpensesIncometotalfee = U.expressfee + U.operatefee + u.incomeotherfee,//Total revenue costsIncomestatus = U.incomestatus.tochinese (),//Income StatusExceptionmsg = U.exceptionmsg,//waybill Abnormal ReasonWaybillcostid = U.waybillcostid//waybill Cost ID//Exceptiontype = U.exceptiontype//waybill Abnormal status }); //decimal totalprofit = 0m; //total gross margin sum//structure to JSON format delivery varresult =New{itotalrecords=Datasource.count, Itotaldisplayrecords=datasource.recordtotal, Data=data}; returnJson (result, jsonrequestbehavior.allowget); }
In view, set the properties of the DataTables
Bserverside:true, //Specify to fetch data from server side/ /with array subscript, the first column starts at 0, when the table is initialized, the fourth column defaults to descending order: [[2, "DESC"]],
When we click Sort, we can open the firebug of Firefox to view the data
This first column is the column index of the sorted field, and the second field identifies a sort field because the control supports multi-column sorting.
Datatablesrequest class, Inside I encapsulated the processing of these requests. The specific code for this class can be found in the ASP. NET MVC build Project Background UI Framework-7, statistical report
String Strsortfield = dicsort.where (x = = X.key = = Parm. Sortcolumns[0]. Index). Select (x = x.value). FirstOrDefault ();
String strsortdire = Parm. Sortcolumns[0]. Direction = = Sortdirection.asc? "ASC": "DESC";
ASP. NET MVC build Project Background UI Framework-9, server-side sort