Skip to content

Instantly share code, notes, and snippets.

@3gcodes
Created July 7, 2009 18:19
Show Gist options
  • Select an option

  • Save 3gcodes/142261 to your computer and use it in GitHub Desktop.

Select an option

Save 3gcodes/142261 to your computer and use it in GitHub Desktop.
def gridList = {
Integer page = Integer.parseInt(params.page)
Integer rows = Integer.parseInt(params.rows)
Integer numRecords = Color.count()
Integer totalPages = 0
if (numRecords > 0) {
totalPages = Math.ceil(numRecords / rows);
}
if (page > totalPages) {
page = numRecords;
}
Integer limit = rows * page - rows;
if (limit < 0) limit = 0;
def colors = Color.createCriteria().list() {
and {
if (params.name) {
like("name", "%${params.name}%")
}
if (params.description) {
like("description", "%${params.description}%")
}
}
maxResults(rows)
firstResult(limit)
order("${params.sidx}", "${params.sord}")
}
colors = colors.collect {
[cell: [it.name, it.description], id: it.id]
}
def jsonColors = [page: "${params.page}", records: rows, rows: colors, total: totalPages]
render jsonColors as JSON
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment