2011-09-22 40 views
4

如何將排序順序設置爲DESC作爲默認值?這類並沒有真正做任何事情,但讓postedAt唯一的排序項:播放框架:排序crud表字段

<div id="crudListTable"> 
    #{crud.table fields:['title', 'postedAt'], sort:['postedAt']} 
     #{crud.custom 'postedAt'} 
      ${object.postedAt.format("dd-MM-yyyy")} 
     #{/crud.custom} 
    #{/crud.table} 
</div> 

回答

4

,如果你願意,你可以在實體做到這一點:

@Entity 
public class Course { 
    ... 
    @ManyToMany 
    @OrderBy("lastname ASC") 
    public List<Student> students; 
    ... 
} 
+0

謝謝,這工作。 – vegardoj

0

你能嘗試到order屬性設置爲DESC

#{crud.table fields:['title', 'postedAt'], sort:['postedAt'], order: 'DESC'} 
    ... 
#{/crud.table} 
+0

沒有做出任何差別。通過將params添加到請求對象來解決它。 – vegardoj

0

這裏是我的黑客:

你要做的第一件事情就是要實現對所需的類可比進行排序,並進一步創建一個compareTo方法。

接下來,在您的項目中輸入crud模塊。在app/views/tags.crud中,您會找到一個名爲relationField.html的文件,它處理添加關係的字段。該文件分爲兩部分,一部分用於創建具有multiple = true的選擇框,另一部分用於創建下拉選擇框。如果你想要這兩種排序,你將不得不在這兩種情況下進行編輯。

替代%{ _field.choices.each() { }%{ _field.choices.sort().each() { }%(基本上增加了排序集合的groovy語法),並且輸入字段將被排序。

的Java類的

完整的示例:

引用類:

@Entity public class Book extends Model {

@Required 
public String title; 

@Required 
@ManyToMany(cascade=CascadeType.PERSIST) 
public List<Author> authors; 

@Required 
@ManyToOne 
public Publisher publisher; 

//omitted 

}

引用的類:

public class Author extends Model implements Comparable {

@Required 
public String firstName; 
@Required 
public String lastName; 

public int compareTo(final Author otherAuthor) { 
    if (this.lastName.equals(otherAuthor.lastName)) { 
     if (this.firstName.equals(otherAuthor.firstName)) { 
      return 0; 
     } else { 
      return this.firstName.compareTo(otherAuthor.firstName); 
     } 
    } else { 
     return this.lastName.compareTo(otherAuthor.lastName); 
    } 
} 
//omitted 

}

這種結構與relationField.html黑客相比會使選擇中的可能性出現排序。