Wednesday, April 15, 2009

A simple way to customize format for GrailsUI DataTable Cells

I was playing around with grails-ui these days.I really like this plugin, it makes my life easy.

After somedays digging, I find a simple way to custom formatting for DataTable cells. It is so simple that I think you will understand it quickly after reading the following controller action code. There is nothing different in GSP, so its code is omited.
def load = {
params.max = Math.min( params.max ? params.max.toInteger() : 10, 100)
def fields=[]
Question.list(params).each{
fields << [
id: it.id
,title: it.title
,dateCreated: it.dateCreated
,lastUpdated: it.lastUpdated
,closed: it.closed
,updateAction: "<A href='/codeline/question/edit/${it.id}'>update</A>"
,deleteAction: "<A href='/codeline/question/delete/${it.id}'>delete</A>"
]
}
response.setHeader("Cache-Control", "no-store")
def result= [ totalRecords: Question.count(), results: fields]
render result as JSON
}
Do you follow me? That's right! It is "returning html in the result". Be careful, if the html is complex, the best way is to check the YUI Document.

No comments: