Hi i would like to know how to create custom values for the dataTable. For example I want to do some calculations for the values that will be placed in the dataTable. But what happens is that I get an error: ERROR errors.GrailsExceptionResolver - Executing action [dataTableJSON] of controller [com.MeetingController] caused exception: org.hibernate.QueryException: could not resolve property: editedDate of: com.Meeting org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [dataTableJSON] of controller [com.MeetingController] caused exception: org.hibernate.QueryException: could not resolve property: editedDate of: com.Meeting.
It cannot sort properly the specified field for the list map if it isn't a field of the domain class. Okay, for example i passed a static key-value pair of "fooKey: 2; " in the list map that will be passed as a JSON. What happens is that it can't figure out how to sort it since it isn't an attribute of the domain class. or even if the key has the same name in the domain class (eg., editedDate) but if we do some calculations or change stuff here (eg., new Date()-it.editedDate) it still can't figure out how to sort these values properly
I really don't know what's the problem since I'm a noob here in grails, web dev, hibernate, and yui javascript stuff. I would appreciate if you could help me figure out or understand some concepts here that I'm not yet familiar of.
What I want to do is to sort the list of meetings in order of the recent update. SO given the lastEdited field of the Domain Class Meeting, I can sort it that way with sortOrder: "desc" but what happens is if I click the next page (or page 2 for that matter), the new ordering will become "asc" which is contrary to what the ordering of the first list. For example:
Meeting A , last edited @ 3:01pm Meeting B , last edited @ 3:02pm Meeting C , last edited @ 3:03pm Meeting D , last edited @ 3:04pm
so if the datable is sorted in descending order by editedDate with a maximum of two rows per page. the result will be:
First Page (current page shown)
- Meeting D
- Meeting C
Second Page
- Meeting B
- Meeting A
But what happens after page 2 is clicked, it will become:
First Page
- Meeting A
- Meeting B
Second Page (current page shown)
- Meeting C
- Meeting D
instead of showing the following second page
First Page
- Meeting D
- Meeting C
Second Page (current page shown)
- Meeting B
- Meeting A
So I'm thinking of a workaround so that I will be needing data that will use "asc" order instead of "desc" so that the list of meetings will be ordered by recently editted. And that is to subtract the current time with the editedDate attribute of Meeting.Hmmm.. it's like saying that i can order the list of meetings by descending order with the editedDate or i could use an ascending order of meetings by their "ago" time (ie, the time passed starting the time now and the time it was last editted, new Date().getTime()- it.editedDate ). But the problem here is that if I tamper the value of the editedDate, the table can't sort it properly; hence, the aforementioned error.
Ok, so my main problem is how to sort using the gui:dataTable by recently editted Meetings and would work properly with pagination.
Sub problems:
- using a sortOrder:"desc" with the pagination, since it's default are "asc"
- how to add a customized value of the data Table so that it can sort properly if i clicked the headers
Sorry for the long inquiry. Thanks in advance!
Domain Class
Class Meeting{
String venue
...
Long editedDate
}
Controller Class
Class MeetingController {
...
def dataTableJSON = {
def meetingList = Meeting.list(params)
meetingList.each {
list << [
id: it.id,
...
venue: it.venue,
editedDate: new Date() - it.editedDate
]
}
def data = [
totalRecords: sizList.totalCount,
results: list
]
render data as JSON
}
}
show.gsp
<div id="single" class="yui-skin-sam">
<gui:dataTable
controller="sizing" action="dataTableJSON"
columnDefs="[
[key:'id', type:'number', sortable:true, width: 50, label:'ID'],
...
[key:'venue', sortable:true, width: 50, label:'Venue'],
[key:'editedDate', sortable:true, width: 50, label:'ID']
]"
sortedBy="editedDate"
sortOrder="desc"
rowClickNavigation="true"
rowsPerPage="4"
/>
</div>