The use of the G:paginate page label for the grails framework

Source: Internet
Author: User



The grails I used was 2.4.4.



The version downstream of a label g:paginate



The following parameters are available under this tab: Total (items that must be filled in), Controller, action, prev, Max, offset, and so on, which I use to refer to the API documentation for detailed parameters.



Normal paging: (Tsystemparam is a domain class of my Code)



Background code: Write the method that needs to be executed under the controller



params.max=5//the params parameter with a map set Key=max, value=5, the number of data bars displayed per page



\ \ Jump to the SHOWSYSPARAMLIST.GSP page, pass the map collection to the foreground with the total number of all the data and data found, be sure to pass in the params parameter when using the list method, because the params parameter sets the amount of data displayed per page and offset (offset, if not set MA The default value for X and offset is 10, and when Max is set, offset can automatically adjust the offset based on the data. The total number of statistics must be passed to the front desk, with the front desk to receive all.
Render (view: "Showsysparamlist", model:[sys:tsystemparam.list (params), SysCount:Tsystemparam.count ()])



Paged with conditions



Add a map collection to the params key=max,value=5



params.max=5;



//grails's HibernatecriteriaBuilder instance, which can be used to build a criteria query.  



def C = Tsystemparam.createcriteria ()
The params value must be there, otherwise the TotalCount method cannot be used



def results = c.list (params) {
Like ("Name", "%w%")



can take other criteria query or sort, my only use of fuzzy query the rest of the omitted


//and {
  //      between("balance", 500, 1000)
    //    eq("branch", "London")
    //}
    //maxResults(10)
    //order("holderLastName", "desc")

  }





The TotalCount method can use the params only if the def results = c.list (params) {passed to the list method params parameter is used instead of the max:5,offset:0
Render (view: "Showsysparamlist", Model:[syst:results, SysCount:results.totalCount])



Front code: Just add the tag to



<g:paginate next= "Next" prev= "previous" controller= "System" action= "Sysparamlist" total= "${syscount}"/>



Total receives the number of queries that the controller passes over, and if Max and offset are not set in the foreground, you can add the max and offset parameters under the P:paginate tab, and the effect is added to the controller





















The use of the G:paginate page label for the grails framework


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.