Hi,
I have a grails app developed. Herein, I have a page which accepts data and as per the data . goes to the list action, fires an sql, populates the data into reconciliationInstance object and displays it in list.gsp.
In my list.gsp, I have,
<g:sortableColumn property="access"
title="${message(code: 'reconciliationInstance.access.label', default: 'Access')}"
style="width: 10px" defaultOrder="desc"/>
However, when I click on the "Amount" heading, it takes me back to the list action again.
I have around 15 columns in the page and want to have sorting for all of them. Am I missing something here?? To rectify this issue ,I wrote the below code. Redirected to action sort. But theres something wrong here I believe.
def sort = {
if (!params.sort) params.sort = "title"
if (!params.order) params.order = "asc"
def reconciliationInstanceList = new ArrayList<Reconciliation>()
reconciliationInstanceList=session["reconciliationInstanceList"]
order(params.sort, params.order)
[reconciliationInstanceList: reconciliationInstanceList]
}
I have saved reconciliationInstanceList in a session. Any Advice/Inputs?
My list action code is as below.
def list ={
//Taking parameters entered in the previous page
def odcNum=params.odcNum
def odcDate=params.odcDate
def date=null
def reconciliationInstance = new Reconciliation()
reconciliationInstance.properties=params
//Validation if all parameters have been entered by the user
if (reconciliationInstance.validate()) {
def results
SimpleDateFormat sdfSource = new SimpleDateFormat("dd-MMM-yyyy")
if(odcDate instanceof Date) {
date = sdfSource.format(odcDate);
}else{
date = odcDate
}
//Query to be fired. I have altered this query a bit. My actual query returns around 15 parameters
String odcData="select odc_access from odc_manager where odc_date=to_char('" + date + "') and odc_num like trim('" + odcNum + "')"
def reconciliationInstanceList = new ArrayList<Reconciliation>()
Sql sql = new Sql(dataSource)
results = sql.eachRow (odcData)
{
def reconciliation = new Reconciliation()
reconciliation.setAccess it.access
reconciliationInstanceList.add reconciliation
session["reconciliationInstanceList"]=reconciliationInstanceList
}
[reconciliationInstanceList: reconciliationInstanceList]
}
else {
render(view: "search", model: [reconciliationInstance: reconciliationInstance])
}
}
BTW I am a novice at grails. Therefore, you would find a bit of java in my code. Somethings missing in my code? Therefore sort doesnt work. Inputs?