Combining paging applications in Extjs4 with the front and back ends
This article describes how to use pages in Extjs4 in combination with the front and back ends. The specific example is as follows. If you are interested, refer
Foreground:
The Code is as follows:
Ext. define ('gs. system. role. store. rolegridstore ',{
Extend: 'ext. data. store ',
Model: 'gs. system. role. model. RoleGridModel ',
Id: 'Role storeid ',
PageSize: 4, // page size
Proxy :{
Type: 'ajax ',
Url: '/gs_erp/roleAction! GetRoleList ',
Reader :{
Type: 'json ',
Root: 'rows ',
TotalProperty: 'Total'
}
},
Sorters :[{
Property: 'id', // sorting Field
Direction: 'asc '// default asc
}],
AutoLoad: {start: 0, limit: 4} // start indicates the number of entries on each page.
});
Store. loadPage (1); // load the first page
Background:
The Code is as follows:
Private int limit; // number of entries per page
Private int start; // the data from which the query starts.
Private int total; // The total number of items.
/**
* Search for all roles
*/
Public void getRoleList ()
{
List <Role> roleList = new ArrayList <Role> ();
StringBuffer toJson = new StringBuffer (); // used to store json data
System. out. println (start + "," + limit + "," + total );
Try
{
RoleList = (List <Role>) pageServiceImpl. commonPagination (Role. class, "", start, limit );
Total = pageServiceImpl. getTotalNum (Role. class ,"");
ToJson. append ("{total:"). append ("" + total + ""). append (", success: true,"). append ("start :")
. Append ("" + start + ""). append (",");
ToJson. append ("rows :[");
For (int I = 0; I <roleList. size (); I ++)
{
ToJson. append ("{id :"). append ("'"). append ("" + roleList. get (I ). getId () + ""). append ("'")
. Append (", name:"). append ("'"). append ("" + roleList. get (I). getName () + "")
. Append ("'"). append (", desc :"). append ("'"). append ("" + roleList. get (I ). getDesc () + "")
. Append ("'"). append ("}");
If (I <roleList. size ()-1)
{
ToJson. append (",");
}
}
ToJson. append ("]}");
} Catch (Exception e1)
{
// TODO Auto-generated catch block
E1.printStackTrace ();
}
Try
{
Response. setHeader ("Cache-Control", "no-cache ");
Response. setContentType ("text/json; charset = UTF-8 ");
Response. getWriter (). print (toJson );
System. out. println (toJson );
} Catch (IOException e)
{
// TODO Auto-generated catch block
E. printStackTrace ();
}
}