英文:
Grails Sortable Column Issue
问题
class Role implements Serializable {
// 这是我的领域类
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()]);
} // 这是控制器中渲染视图页面 'indexList' 的方法
<div class="col-md-12 main-header">Role List</div>
<!-- 这是要被渲染的 'view' gsp 页面 -->
<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>
在这里,当我点击可排序的列 'authority' 时,排序未执行,页面会刷新,URL 如下:
role/indexList?sort=authority&order=asc
非常感谢您的帮助。同时请注意我对 Grails 框架还不够熟悉。
英文:
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
答案1
得分: 0
你可能想要使用 Role.list(params)
替代 Role.findAll()
。
英文:
You probably want Role.list(params)
instead of Role.findAll()
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论