Playback structure: sorting crud table fields

How to set default sort order in DESC? This view actually does nothing except make postedAt only the element to be sorted:

<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
source share
3 answers

You can do this in Entity if you want:

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

Can you set the order attribute to DESC ?

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

Here is my hack:

The first thing you need to do is implement Comparable in the class you want to sort, and then create the compareTo method.

Then enter the crud module in your project. In the application /views/tags.crud you will find a file called relatedField.html that processes the fields for adding relationships. This file is divided into two parts: one for creating custom boxes with several = true and one for creating drop-down menus. If you want both of these sorts to be edited in both cases.

Replace %{ _field.choices.each() { } with %{ _field.choices.sort().each() { }% (basically adding groovy syntax to sort the collection) and the input fields will be sorted.

Full example of Java classes:

Class Link:

@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 

} Code>

Associated class:

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 

} Code>

This structure, compared to hack on relationField.html, will make the selection options sorted.

0
source

All Articles