Grails_filterpane插件使用

Grails_filterpane插件使用

Grails_filterpane插件使用


filterpane 插件可以根据Domain Class 生成查询界面并从数据库中进行查询,使用方面比较简单。

通过命令 grails install-plugins filterpane 进行安装,

在list.gsp面页中头面加入

<filterpane:filterPaneIncludes />

引入资源

<filterpane:currentCriteria domainBean= "AddressList" removeImgDir= "images" removeImgFile= "bullet_delete.png" />

显示当前查询条件,domainBean 需要加入包名.

<g:paginate total= "${addressListInstanceTotal}" params= "${filterParams?filterParams:params}"/>

修改grails 生成的页面,支持查询结果集进行翻页.在没有使用filterpane时也需要将参数传递到后台,默认不支持查询结果集翻页。

<g:paginate total= "${addressListInstanceTotal}" params= "${params}"/> <filterpane:filterButton textKey= "fp.tag.filterButton.text" appliedTextKey= "fp.tag.filterButton.appliedText" text= "Filter Me" appliedText= "Change Filter" />

显示查询按钮,textKey与appliedTextKey是在资源文件messages-filterpane.properties中指定的,完全支持国际化。

<filterpane:filterPane domainBean= "cn.xiangyunsoft.jltv.AddressList" additionalProperties= "identifier" titleKey= "fp.tag.filterPane.titleText" /> <filterpane:filterPane domainBean= "AddressList" additionalProperties= "identifier" titleKey= "fp.tag.filterPane.titleText" />

生成查询条件界面.

<filterpane:filterPane domainBean= "AddressList" additionalProperties= "identifier" filterPropertyValues= "{[createDate:[precision:'day',dateFormat:'yyyy-MM-dd'],expDate:[precision:'day']]}" filterProperties= "number,networkType,networkName,channel,createDate,expDate,psnName,psnTel,psnMtel,state" titleKey= "fp.tag.filterPane.titleText" />

filterProperties 指定查询界面显示的条件,filterPropertyValues字段值的格式与默认值。

在Controller中加入下面代码:

def filterService 
def filter = { if(!params.max) params.max = 10 render( view:'list', model:[ addressListInstanceList: filterService.filter( params, AddressList ), addressListInstanceTotal: filterService.count( params, AddressList ), filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), params:params ] )def filter = {  if(!params.max) params.max = 10 render( view:'list', model:[ addressListInstanceList: filterService.filter( params, AddressList ), addressListInstanceTotal: filterService.count( params, AddressList ), filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), params:params ] ) }     }

你可能感兴趣的:(Grails_filterpane插件使用)