///
/// Object sorting comparator factory
/// public class ContributivePerson_SortComparerFactory
{
// /
///
/// ///
/// < ;returns>
public IComparer
GetSortComparer(string FieldName, ESortType eSortType)
{
IComparer )
{
case "BALDEPER"://Balance Payment Period
IComparer = new ContributivePerson_BALDEPER_Comparer(eSortType);
break;
case "INV"://Investor
IComparer = new ContributivePerson_INV_Comparer( eSortType);
break;
}//switch
return IComparer;
}
}//class
Let’s use it below. This method is a The newly written method on the Webservice interface side. We see that the red code segment is the sorting block, and the green annotation is the filtering code block (the code has been omitted)
///
/// Table filling server with paging function (with sorting)
// / ///
///
Number per page param>
///
Current page
///
Sort type: "ASC" ,"DESC "
///
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Load_ContributivePerson_Table_Sort(string FlowID, int PageCount,
int CurrentPage, string SortType, string SortFieldName)
{
List
list = new List();
list = objBusinessFacade.GetTB_WEB_NZ_INVESTMENT_CollectionByFlowID(Flow ID);
ContributivePerson_SortComparerFactory objFactory = new ContributivePerson_SortComparerFactory();
IComparer objSort = null;
if (SortType.ToUpper().Trim() == "ASC")
{
objSort = obj Factory .GetSortComparer(SortFieldName,ESortType.ASC);
}
else if (SortType.ToUpper().Trim() == "DESC")
{
objSort = objFactory.GetSortComparer(SortFieldName, ESortType.DESC);
}
list.Sort(objSort);
//Part of the code is omitted. For omitted code, please refer to the previous article
return new JavaScriptSerializer().Serialize(list) ;
}
By adding a comparator, we can achieve arbitrary sorting on the generic list object without the need to sort through SQL statements. This can be achieved by just adding the necessary parameters on the client page. The middle layer server has already implemented all the core. The client code only needs to determine which column needs to be sorted. At the same time, pay attention to the [Homepage] [Next Page] and other buttons. Just turn the page in the order of sorting. The client code here is omitted