JQGrid
Dependency :
compile ":jqgrid:3.8.0.1"
Summary
Installation
grails install-plugin jqgrid
Description
Overview
Provides simple integration with the jquery jqgrid library. More details on JQGrid can be found here: http://www.trirand.com/blog/Contact
Please report bugs and feature requests in JIRA or at the Grails-User Mailinglist.The 3.8.x release is not backwards compatible with the 3.7.x release. 3.8.x has been changed so all taglib attributes are the same as the actual jqgrid options. Future 3.x releases will be backward compatible with 3.8.0. See http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jqgriddocs for grid options.
Breaking Changes between 3.8.x and 3.7.x.
The following taglib attributes have been remove- listUrl
- Use the url attribute instead.
- editUrl
- Use the editurl attribute instead
- sortName
- Use the sortname attribute instead
- viewRecords
- Use the viewrecords attribute instead
- filterToolBar, searchOnEnter
- This functionality has moved to <jqgrid:filterToolbar>.
- standardAddButton, standardEditButton, standardDeleteButton, standardSearchButton, standardRefreshButton
- These attributes have moved to <jqgrid:navigation add="true" edit="true" del="true" search="true" refresh="true" />.
- resizeOffset
- This attribute has moved to <jqgrid:resize>
Taglibs
There are a few different taglibs in this plugin. You do not need to use all of them. Just use what makes sense for you.- <jqgrid:resources />
- Includes the required javascript and css for the plugin
- <jqgrid:cssResources />
- Includes on the required css for the plugin.
- <jqgrid:scriptResources />
- Includes the required javascript for the plugin
- <jqgrid:grid />
- Main taglib for the plugin. Generates the jqgrid javascript for the grid (Does not generate the <table> tag or pager <div>)
- <jqgrid:wrapper />
- Generates the <table> tag for the grid. Also generates the <div> for the grid pager
- <jqgrid:navigation />
- Used in the body of the <jqgrid:grid /> Generates the pager / navigation buttons for the grid.
- <jqgrid:filterToolbar />
- Used in the body of the <jqgrid:grid /> Enables Toolbar searching just below the header elements.
- <jqgrid:resize />
- Used in the body of the <jqgrid:grid /> Turns on fluid grid http://stevenharman.net/blog/archive/2009/08/21/creating-a-fluid-jquery-jqgrid.aspx
- <jqgrid:addButton />
- Used in the body of the <jqgrid:grid /> tag to include a custom "Add" button.
- <jqgrid:editButton />
- Used in the body of the <jqgrid:grid /> tag to include a custom "Edit" button
- <jqgrid:deleteButton />
- Used in the body of the <jqgrid:grid /> tag to include a custom "Delete" button
- <jqgrid:searchButton />
- Used in the body of the <jqgrid:grid /> tag to include a custom "Search" button
Simple Example
<html>
<head>
<meta name="layout" content="main" />
<jq:resources />
<jqui:resources />
<jqgrid:resources /> <script type="text/javascript">
$(document).ready(function() {
<jqgrid:grid
id="contact"
url="'${createLink(action: 'listJSON')}'"
editurl="'${createLink(action: 'editJSON')}'"
colNames="'First Name', 'Last Name', 'E-mail', 'Phone', 'id'"
colModel="{name:'firstName', editable: true},
{name:'lastName', editable: true},
{name:'email', editable: true},
{name:'phone', editable: true},
{name:'id', hidden: true}"
sortname="'lastName'"
caption="'Contact List'"
height="300"
autowidth="true"
scrollOffset="0"
viewrecords="true"
showPager="true"
datatype="'json'">
<jqgrid:filterToolbar id="contact" searchOnEnter="false" />
<jqgrid:navigation id="contact" add="true" edit="true"
del="true" search="true" refresh="true" />
<jqgrid:resize id="contact" resizeOffset="-2" />
</jqgrid:grid>
});
</script>
</head>
<body>
<jqgrid:wrapper id="contact" />
</body>
</html>Notice how the "id" of the different tags match? By using this convention you don't need to think about DOM id's
.......
class ContactController {
........
def listJSON = {
def sortIndex = params.sidx ?: 'name'
def sortOrder = params.sord ?: 'asc'
def maxRows = Integer.valueOf(params.rows)
def currentPage = Integer.valueOf(params.page) ?: 1
def rowOffset = currentPage == 1 ? 0 : (currentPage - 1) * maxRows def contacts = Contact.createCriteria().list(max: maxRows, offset: rowOffset) {
if (params.firstName)
ilike('firstName', "%${params.firstName}%") if (params.lastName)
ilike('lastName', "%${params.lastName}%") if (params.email)
ilike('email', "%${params.email}%") if (params.phone) {
ilike('phone', "%${params.phone}%")
}
order(sortIndex, sortOrder).ignoreCase()
} def totalRows = contacts.totalCount
def numberOfPages = Math.ceil(totalRows / maxRows) def results = contacts?.collect {
[
cell: [it.firstName, it.lastName, it.email, it.phone],
id: it.id
]
} def jsonData = [rows: results, page: currentPage, records: totalRows, total: numberOfPages]
render jsonData as JSON
}
......
}
Demo Pages
The plugin includes a demo page / controller that shows a few of the features of the plugin.- Grouping
- Subgrid
- Toolbar filtering
- Many more...
Releases
Version 3.8.0 release 10/11/2010
- Upgraded to JQGrid 3.8
- Subgrid and Grouping support
- If you want to use the given example in Grails 2.0.* then remove the ignoreCase() from the listJSON method as it is not supported and results in error.
- GRAILSPLUGINS-2520
- GRAILSPLUGINS-2521
- GRAILSPLUGINS-2555
Version 3.7.2.1 release 9/27/2010
- Add ability to use all JQGrid event handlers GRAILSPLUGINS-2518
- Fixed issue with templates not including 'plugin' directive GRAILSPLUGINS-2519
Version 3.7.2 release 9/19/2010
- Initial Release
- Based on jqgrid version 3.8.2