ASP. NET MVC build Project Background UI Framework-9, server-side sort

Source: Internet
Author: User

  1. ASP. NET MVC build Project Background UI Framework-1, background main frame
  2. ASP. NET MVC build Project Background UI Framework-2, menu effects
  3. ASP. NET MVC build Project Background UI Framework-3, panel folding and unwinding
  4. ASP. NET MVC build Project Background UI Framework-4, TAB multi-page support
  5. ASP. NET MVC build Project Background UI Framework-5, demo demo Controller and view interaction
  6. ASP. NET MVC build Project Background UI Framework-6, customer management (add, modify, query, paging)
  7. ASP. NET MVC build Project Background UI Framework-7, statistical report
  8. ASP. NET MVC build a project background UI framework-8. Pass some data from the selected data row in the view into the controller
  9. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.