Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:26:45+00:00 2026-06-15T14:26:45+00:00

Is there any simple solution to get g:pagination and g:sortableColumn for children elements in

  • 0

Is there any simple solution to get g:pagination and g:sortableColumn for children elements in parent show view working?

It is well explained in the documentation how to do pagination and sortable columns for current domain in list, and it works, but I cant get it to work in situation described in question.

Edit: I updated the example

Now only thing that is not working is pagination. When I click on the next page link the list is gone and ${childrenistSize} prints 0.

Simple example:

Parent domain

class Parent {

    String name

    static hasMany = [children: Children]

    static constraints = {
    }
}

Children domain

class Children {

    String first
    int number

    static belongsTo = [parent: Parent]

    static constraints = {
    }
}

Parent list view

<g:each in="${parentList}" var="parent">
    <tr>
        <td>${parent.name}</td>
        <td><g:link controller="parent" action="show" id="${parent.id}">Show</g:link></td>
    </tr>
</g:each>

Parent show view

<table>
    <thead>
        <tr>
            <g:sortableColumn property="first" title="First"/>
            <g:sortableColumn property="number" title="Number"/>
        <tr>
    </thead>
    <tbody>
        <g:each in="${childrenList}" var="child">
            <tr>
                <td>${child.first}</td>
                <td>${child.number}</td>
            </tr>
        </g:each>
    </tbody>
</table>
<g:paginate total="${childrenListSize}"/>

ParentController

class ParentController {

    def index() { }

    def list() {
        [parentList: Parent.list()]

    }

    def show() {
        params.max=3
        def parentInstance = Parent.get(params.id)
        def childrens = Children.createCriteria().list(params) {
          eq('parent', parentInstance)
        }
        [parentInstance : parentInstance , childrenList: childrens, childrenListSize: childrens.totalCount]
     }

}

Some BootStrap test elements

    Parent parent1 = new Parent(name: "TestParent1")
    Parent parent2 = new Parent(name: "TestParent2")

    Children child1 = new Children(first: "Bob", number: "1")
    Children child2 = new Children(first: "John", number: "2")
    Children child3 = new Children(first: "Igor", number: "3")
    Children child4 = new Children(first: "Lucy", number: "4")
    Children child5 = new Children(first: "Lisa", number: "5")

    Children child6 = new Children(first: "Bob", number: "12")
    Children child7 = new Children(first: "John", number: "24")
    Children child8 = new Children(first: "Igor", number: "33")
    Children child9 = new Children(first: "Lucy", number: "42")

    parent1.addToChildren(child1).addToChildren(child2).addToChildren(child3).addToChildren(child4).addToChildren(child5)
    parent2.addToChildren(child6).addToChildren(child7).addToChildren(child8).addToChildren(child9)

    parent1.save()
    child1.save()
    child2.save()
    child3.save()
    child4.save()
    child5.save()
    parent2.save()
    child6.save()
    child7.save()
    child8.save()
    child9.save()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:26:46+00:00Added an answer on June 15, 2026 at 2:26 pm

    The problem is that you don’t have a column named children.name in the Children domain class. What you need to do is identify in your controller that you must sort by the name column.

    I can see that you show a list of childrens in the show action of Parent, and the parent isn’t sortable in this action, so will be a simple change:

    def show() {
      def parentInstance = Parent.get(params.id)
      def childrens = Children.createCriteria().list(params) {
        eq('parent', parentInstance)
      }
      [parentInstance : parentInstance , childrenList: childrens, childrenListSize: childrens.totalCount]
    }
    
    
    <p>Parent: ${parentInstance.name}</p>
    <table>
        <thead>
            <tr>
                <g:sortableColumn property="name" title="Name"/>
            <tr>
        </thead>
        <tbody>
            <g:each in="${childrenList}" var="child">
                <tr>
                    <td>${child.name}</td>
                </tr>
            </g:each>
        </tbody>
    </table>
    <g:paginate max="1" total="${childrenListSize}"/>
    

    Note that I changed the property name since it’s just name and not children.name. Also, i pass the params to the criteria to make the sort works.

    I not tested this, so can be a typo anywhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is very simple: Is there any solution to install xCode, or equivalent,
Is there any (simple) way to get some control of the order in which
Is there any simple way to get amount of data transferred from database to
Is there any simple way how to draw obliquely strike through on TextView? Now
Is there any simple way how to initialize String in Objective-C with int such
Is there any simple way to create instance of modal DialogBox with single text
Is there any simple way to tell if UNC path points to a local
In git, is there any (simple) way to modify the index so that only
As a follow up question to my last one , is there any simple
Are there any tool / simple method to read the properties (Ex : Compression

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.