格雷尔排序列问题

huangapple go评论73阅读模式
英文:

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: &quot;indexList&quot;, model:[roleInstanceList: Role.findAll()])
}   // this is the method in the controller that renders the view page &#39;indexList&#39;
&lt;div class=&quot;col-md-12 main-header&quot;&gt;Role List&lt;/div&gt;
//this is my &#39;view&#39; gsp page to be rendered 
&lt;table class=&quot;table manage-table&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
**&lt;g:sortableColumn property=&quot;authority&quot;
title=&quot;${message(code: &#39;role.authority.label&#39;, default: &#39;authority&#39;)}&quot; /&gt;**
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;g:each in=&quot;${roleInstanceList}&quot; status=&quot;i&quot; var=&quot;roleInstance&quot;&gt;
&lt;tr id=&quot;${roleInstance.id}&quot; class=&quot;${(i % 2) == 0 ? &#39;even&#39; : &#39;odd&#39;}&quot;&gt;
&lt;td&gt;
${fieldValue(bean: roleInstance, field: &quot;authority&quot;)}
&lt;/td&gt;
&lt;/tr&gt;
&lt;/g:each&gt;
&lt;/tbody&gt;
&lt;/table&gt;

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().

huangapple
  • 本文由 发表于 2020年10月2日 20:01:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/64171191.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定