tags:

views:

53

answers:

2

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?

+1  A: 

it should take you back to the list action, but the params passed to the action will let it know how to sort the resulting model.

the behavior is correct, I assume your code in the list action is not coded properly... You might want to include that code if you want additional guidance.

See sample list action

http://www.grails.org/GSP+Tag+-+sortableColumn

Aaron Saunders
Thanks Aaron for looking into this. I have edited my actual question to have the list action code as well. The application has a create.gsp.User enters, odcNum and odcDate. On submitting the form, the list action is called.Here the parameters are retrieved, query run and data populated in the reconciliationInstanceList. This is given back to the list.gsp and we get data displayed as a table.The table has around 15 rows, and when the user clicks on the headings, it should sort and display the data. My code is missing something. Please advice.
Bob
A: 

Found a work around for this. Passed the sort order (params.order) to the sql query and let the query do the sorting. Displayed the results on the gsp then.

If theres any other way out, do let me know.

Thanks, Bob

Bob