grails findAll paginate and sortablecolumn
2008-11-18 09:49
337 查看
if(!params.max) params.max = 20
if (!params.offset) params.offset = 0
if (!params.sort) params.sort = 'id'
if (!params.order) params.order = 'asc'
def paginateParams = [max: new Long(params.max), offset: new Long(params.offset)]
return [ testProjectList: TestProject.findAll("from TestProject as b where b.createBy.group=? order by b.id ${params.order}",[User.findByUsername(request.getRemoteUser()).group],paginateParams) ]
要使得sortablecolumn能正常排序 一定加上order by b.id ${params.order} 如使得pagnate正常分页 pagenateparams是必须的 grails里有个bug findall不能加params的参数: findAll(args,args,Params)//不能转换integer错误 而findAllBy加params参数是可以的 可以避免上述问题
对于findAllBy 则只需要传入params参数即可
if(!params.max) params.max = 20
if (!params.offset) params.offset = 0
if (!params.sort) params.sort = 'id'
if (!params.order) params.order = 'asc'
render (view:'testCaseResultResult',model:[testCaseResultList : TestCaseResult.findAllByRunidAndResult(params.id,"Pass",params)])
对于pagenate: id (optional) - The id to use in the link id的作用和g:link中id一样
<div class="paginateButtons">
<g:paginate total="${TestCaseResult.count()}" id="${params.id}"/>
</div>
对于pagnate和sortable column的参数
<div class="paginateButtons">
<g:paginate total="${TestCaseResult.count()}" id="${params.id}" params="${[moduleId:params.moduleId,author:params.author]}"/>
</div>
<g:sortableColumn property="moduleid" title="Moduleid" params="${[moduleId:params.moduleId,author:params.author]}"/>
对于条件查找 多种条件
def c = TestCaseResult.createCriteria()
def results = c {
and{
eq("runid",params.id.toInteger())
or{
eq("result","GoNextIssue")
eq("result","Failed")
}
}
order(params.sort, params.order)
}
只要熟悉了分页和查找的内在逻辑 就很容易实现分页 不比拘泥于findAllBy 参数的传入
NoResultList为任意的一个list列表
def endOffset = params.offset.toInteger()+params.max.toInteger() #取列表中的某些值 区间的确定
if(pagnateCount< endOffset) #如果到了最后一页 则最后的数值赋予endOffset
endOffset=pagnateCount
render(view:'list',model:[ testCaseList: NoResultList[params.offset.toInteger()..endOffset],'pagnateCount':pagnateCount,'NoResultId':params.NoResultId])#注意 传入的NoResultList[ ] 里面的下标是从开始到结束的值 因该是当前的offset 到 endOffset
if (!params.offset) params.offset = 0
if (!params.sort) params.sort = 'id'
if (!params.order) params.order = 'asc'
def paginateParams = [max: new Long(params.max), offset: new Long(params.offset)]
return [ testProjectList: TestProject.findAll("from TestProject as b where b.createBy.group=? order by b.id ${params.order}",[User.findByUsername(request.getRemoteUser()).group],paginateParams) ]
要使得sortablecolumn能正常排序 一定加上order by b.id ${params.order} 如使得pagnate正常分页 pagenateparams是必须的 grails里有个bug findall不能加params的参数: findAll(args,args,Params)//不能转换integer错误 而findAllBy加params参数是可以的 可以避免上述问题
对于findAllBy 则只需要传入params参数即可
if(!params.max) params.max = 20
if (!params.offset) params.offset = 0
if (!params.sort) params.sort = 'id'
if (!params.order) params.order = 'asc'
render (view:'testCaseResultResult',model:[testCaseResultList : TestCaseResult.findAllByRunidAndResult(params.id,"Pass",params)])
对于pagenate: id (optional) - The id to use in the link id的作用和g:link中id一样
<div class="paginateButtons">
<g:paginate total="${TestCaseResult.count()}" id="${params.id}"/>
</div>
对于pagnate和sortable column的参数
<div class="paginateButtons">
<g:paginate total="${TestCaseResult.count()}" id="${params.id}" params="${[moduleId:params.moduleId,author:params.author]}"/>
</div>
<g:sortableColumn property="moduleid" title="Moduleid" params="${[moduleId:params.moduleId,author:params.author]}"/>
对于条件查找 多种条件
def c = TestCaseResult.createCriteria()
def results = c {
and{
eq("runid",params.id.toInteger())
or{
eq("result","GoNextIssue")
eq("result","Failed")
}
}
order(params.sort, params.order)
}
只要熟悉了分页和查找的内在逻辑 就很容易实现分页 不比拘泥于findAllBy 参数的传入
NoResultList为任意的一个list列表
def endOffset = params.offset.toInteger()+params.max.toInteger() #取列表中的某些值 区间的确定
if(pagnateCount< endOffset) #如果到了最后一页 则最后的数值赋予endOffset
endOffset=pagnateCount
render(view:'list',model:[ testCaseList: NoResultList[params.offset.toInteger()..endOffset],'pagnateCount':pagnateCount,'NoResultId':params.NoResultId])#注意 传入的NoResultList[ ] 里面的下标是从开始到结束的值 因该是当前的offset 到 endOffset
相关文章推荐
- [Twitter] Given a matrix with all elements sorted on each individual row and column find
- Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times
- [LinkedIn] Array of size n and an int k, find all elements that appear/occur more than n/k times
- LeetCode Find All Duplicates in Array and Find Disappeared Numbers in Array
- How to learn C++ and find all STL Algorithm reference
- Grails GORM findAll动态查询条件
- re.findall and re.search的区别
- Rails2中实现表格排序(整合sortable_column_headers和will_paginate)
- Vi / VIM: Find And Replace All Text Substitute Command
- mysql query to find the maximum 3 values from a column and group by on other column
- Find out all the Primary Key and Foreign Key Constraints in a table
- [每日练习] write a function to find the key in a m*n matrix, where each line and column is incremental
- Quickly find all tables/views that have a specific column name
- 【Python】Windows 10 and Unable to find vcvarsall.bat
- T-sql get alll columns name and column type from table
- Find all the prime number between 1 and 100
- Kettle解析JSON错误,We MUST have the same number of values for all paths,We can not find and data with path [$.
- Find out all the elements in A and B such that the A[i]-B[j]=C[k]
- ABAP code to find all the User Exits and BADIs for any transaction
- The project cannot be built until its prerequisite base-service is built. Cleaning and building all projects is recommended