First we need to tweak the controller action so that it doesn’t just return all users. Unless you need to make use of some complicated hql expression, the criteria builder is the easiest way to do this. Here’s what our modified list action will look like now:
Notice that we’re using the filter param values to build our query and passing these values back to the model inside the filters object. The last part of this action uses one of two views. The first one is the main list page (list.gsp) and second one is for ajax requests which returns just the list part (_grid.gsp) of our page. Here’s what these two views might look like:
list.gsp
This is very similar to what we saw in the last post, we’re just adding the filter HTML elements. Next is the grid view:
_grid.gsp
An important thing to note here is that we’re using our filters object and setting the params property of both the pagination tag and each sortable column. This is so these filter parameters are available between requests so we don’t lose our filter options when we sort or page.
Now our last step is to add some jQuery to turn all paging, sorting and filter requests into ajax requests. All pagination and sorting links will be turned into ajax requests. Also, any input elements you add inside the filter box (div.filters) will automatically do an ajax request and update your table.
This code assumes that the grid (div.grid) is directly after the filters box (div.filters). You may need to adjust your jQuery if the structure of your page is different.