Using handler to process pagination
First to create a generic handler, I named Storehandler.ashx, and then its process code is as follows:
public voidProcessRequest (HttpContextContext) {context. Response.ContentType ="Application/json";Varrequestparams = Storerequestparametersint int datasorter["sorter = requestparams.sort; datafilter[] filter = Requestparams.filter; paginguserinfo< Span style= "color:black;" >> employees = getpagedata (start, limit, filter, sorter); Context. Response.Write (json
In this method, we first use HttpContext to create a Storerequestparameters object that contains the start, Limit, Page, Sort, Filter, group, and other parameters.
- Start: Get data records from the first few lines
- Limit: Gets the amount of data, how many rows of data are fetched at one time
- Page: the current page number
- Sort: sorted set of conditions
- Filter: Filtered set of conditions
- Group: Set of conditions for grouping
After acquiring this data, we fetch the qualifying data through Getpagedata and then create an instance of the Paging<t> class that contains the two important attributes of data and totalrecords
- Data collection of type data:ienumerable<t>
- Totalrecords: Total number of data rows for client paging (generating page numbers)
Our code to get the data method is as follows:
PublicPaging<UserInfo> Getpagedata (IntStartIntLimitdatafilter[] filter, [] sorter) {var Userinfolist = userinfo paging< Userinfo> result = Paging<userinfo > (); Result. Totalrecords = Userinfolist.count; Result. Data = Userinfolist.skip (start). Take (limit). ToList (); return result;}
With this handler, we need to retrofit the store:
<Ext:StoreRunat= "Server"Id= "Storeuserinfo"PageSize= "5"Remotefilter= "true"Remotesort= "true" > <Model> <Ext:ModelId= "Model1"Runat= "Server"Idproperty= "Name" > <Fields> <Ext:ModelfieldName= "Name"Type= "String" ></Ext:Modelfield> <Ext:ModelfieldName= "Gender"Type= "String" ></Ext:Modelfield> <Ext:ModelfieldName= "Age"Type= "Int" ></Ext:Modelfield> </Fields> </Ext:Model> </Model><Proxy> <Ext:AjaxproxyUrl= "Storehandler.ashx" > <actionmethods read = "GET "/> <reader > < ext:jsonreader root = "Data"/> </reader > </:AjaxProxy > </ ></ext:Store>
The URL of Ajaxproxy is our handler address. Actionmethods is the request method, and Jsonreader is the reader property, which gets the data root node. This is all based on ExtJS Ajaxproxy, you can read my previous article to understand this aspect: ExtJS 4.2 Tutorial-06: Server Agent (proxy)
Implementation of Pageproxy Paging
Pageproxy is a paging method implemented by Ext.net, unlike the way handler is used, Pageproxy accomplishes pagination by implementing Onreaddata events.
Here we look directly at the code of the store:
<Ext:StoreRunat= "Server"Id= "Storeuserinfo"PageSize= "5"Onreaddata= "Storeuserinfo_readdata" > <Model> <Ext:ModelId= "Model1"Runat= "Server"Idproperty= "Name" > <Fields> <Ext:ModelfieldName= "Name"Type= "String" ></Ext:Modelfield> <Ext:ModelfieldName= "Gender"Type= "String" ></Ext:Modelfield> <Ext:ModelfieldName= "Age"Type= "Int" ></Ext:Modelfield> </Fields> </ext:model> </model> <proxy> < ext:pageproxy></ext:PageProxy< Span style= "color:blue;" > > </proxy></ ext:store >
Then implement Storeuserinfo_readdata in the background code:
Storeuserinfo_readdata (sender, ext.net. UserInfo. GetData (); E.total = Userinfolist.count; Storeuserinfo.datasource = Userinfolist.skip (start). Take (limit). ToList (); Storeuserinfo.databind ();}
Sorting and filtering
As we have mentioned above, the server side can obtain the sort and filter parameters, and then get the corresponding data by processing the sort and filter.
For example, my filter code:
UserInfo. GetData (); (filter) {userinfolist = Userinfolist.findall (m = = M.name = = Item. Value); }}
This will filter every option that matches. The code of sort is more complex, and it has not yet been completed a more generic one, and the garbage code does not post it to the detriment of the public.
Ext.net Study Notes 09:ext.net store usage