Grails Ajax List with Paging, Sorting and Filtering
Adding to my previous post about creating an ajax list with paging and sorting, I’m now going to extend our user list example to include filtering by the user’s name.
Adding to my previous post about creating an ajax list with paging and sorting, I’m now going to extend our user list example to include filtering by the user’s name.
Grails allows you to easily create a view template for all the pages in your application through sitemesh. Making simple HTML tweaks to the default template works if you only have one main content region to your template. Oftentimes though you might want more than this (a content region and a sidebar region for example). Here’s how you can accomplish this.
You can easily add ajax to your grails application using standard g tags, but making a list (table) that supports ajax-enabled sorting and paging is a bit different. Here are the steps I took to make this happen.
A really nice feature of GORM (and Hibernate) is support for inheritance in domain objects. For example if your application has different types of user accounts with specific properties then you can create distinct domain objects that inherit from a User base class that has all the common properties of a user (email, password, etc). Here’s what it might look like if you had a student user type and an admin user type:
In grails you have a lot of control over how specfic controller actions are mapped to urls through the UrlMappings.groovy file. The default behavior is for the urls to look something like this: