Skip to content
Advertisement

Grails Sortable Column Issue

 class Role implements Serializable {
    // this is my domain class
    private static final long serialVersionUID = 1

    String authority

    Role(String authority) {
        this()
        this.authority = authority
    }

    static constraints = {
        authority blank: false, unique: true
    }

    static mapping = {
        cache true
    }
} 




def indexList(){

        render(template: "indexList", model:[roleInstanceList: Role.findAll()])
    }   // this is the method in the controller that renders the view page 'indexList'


     

   

   <div class="col-md-12 main-header">Role List</div>
   //this is my 'view' gsp page to be rendered 
   <table class="table manage-table">
    <thead>
        <tr>
            **<g:sortableColumn property="authority"
                title="${message(code: 'role.authority.label', default: 'authority')}" />**
            
        </tr>
    </thead>
    <tbody>
        <g:each in="${roleInstanceList}" status="i" var="roleInstance">
            <tr id="${roleInstance.id}" class="${(i % 2) == 0 ? 'even' : 'odd'}">

                <td>
                    ${fieldValue(bean: roleInstance, field: "authority")}
                </td>
            </tr>
        </g:each>
    </tbody>
</table>

Here, when I click on Sortable Column ‘authority’ – sorting is not done and I am getting a page refresh with the following URL: role/indexList?sort=authority&order=asc Any help much appreciated. Thanks and a note to point that I am new to grails framework

Advertisement

Answer

You probably want Role.list(params) instead of Role.findAll().

Advertisement