Saturday, April 21, 2007

Grails + Ext Grid Mini Tutorial

Ext Grid component is very easy to use with Grails listing. However you should go over the basic Grids tutorial and then the paging Grid tutorial first.

Because the Grid component talk to your Grails controller with either XML or JSON, you have to use XML or JSON builder. Render your XML data like this:

render(contentType:'text/xml') {
Minutes {
totalCount(totalRecordCount)
for(m in results) {
Minute {
ID(m.id)
Subject(m.subject)
MeetingSummary(m.meetingSummary)
Scribe(m.scribe)
Venue(m.venue)
MeetingStartTime(m.meetingStartTime)
MeetingEndTime(m.meetingEndTime)
}
}
}
That's about the only thing you'd have to do on your Grails controller to output the XML data. Then if you follow through the Grid component example, you should get ya data rows on the Grid. Next enable paging, you need to a few modifications.

Use DomainClass.count() method to get the total number of records. Generate that along with the XML data.

 render(contentType:'text/xml') {
Minutes {
totalCount(totalRecordCount)
for(m in results) {
Minute {
ID(m.id)
Subject(m.subject)
MeetingSummary(m.meetingSummary)
Scribe(m.scribe)
Venue(m.venue)
MeetingStartTime(m.meetingStartTime)
MeetingEndTime(m.meetingEndTime)
}
}
}
In your controller, you need to get 2 params from Grid, "start" and "limit". This is passed by the datastore during load time (Refer to the paging tutorial) . Grails paging need "offset" and "max" to work so we will just assign "start" to "offset" and "limit" to "max".

results = DomainClass.list( [offset:params.start, max:params.limit] )

Well you can also change the default example paging params to "offset" and "max" staightaway instead of reassign them in the controller.

ds.load({params:{offset:0, max:25}});

7 comments:

brianpwolfe said...

thanks for the grails + ext info. I am working on a project, and if you are interested in making some extra money I would like to talk.

email: brianpwolfe@yahoo.com

Seymour Cakes said...

Hi Brian,

Make money? Sure!
But wait, are you a spammer? :D

I think you better delete off your e-mail there, you might get spammed instead.

\:D/

Bruce said...

I was wondering if it would be possible to expand this example to pull in a dataset from two tables. Is this possible? A column from table A, and a column from table B using some sort of inner join?

B.

Anonymous said...

Hi seymour,

thank you for the paging example.

Best regards,
Masiar

grish said...

I like this example and try to use extjs-gwt in eclipse project. This is my first article about extjs-gwt:gxt
See more about How to setup Extjs-gwt on Eclipse.
I think this extjs-gwt article can help beginner to learn.

Papaz büyüsü said...

thanks for the grails + ext info. I am working on a project, and if you are interested in making some extra money I would like to talk.

Papaz büyüsü said...

thanks for the grails + ext info. I am working on a project, and if you are interested in making some extra money I would like to talk.