2015-10-20 75 views
0

我正在使用jqgrid版本4.5.2。以下是我的网格的定义。在列模型中,我有一个名为region的列,其上面应用了过滤器。定制jqgrid过滤器逻辑

jq("#grid").jqGrid({  
url:finalUrl, 
ajaxGridOptions: {cache: false},//added the option to always reload the grid and not to cache the result. 
datatype: 'json',  
mtype: 'GET', 
colNames:[ 'Requestor Name'],  
colModel:[ 
    {name:'requestor',index:'requestor',sortable: true, width:100,editable:false, editrules:{required:true}, editoptions:{size:10}}, 
    {name:'requestorRegion', index:'requestorRegion',sortable: true,width:65,editable:false, editrules:{required:true}, editoptions:{size:8, style: "height: 90%"}, stype:'select', edittype:'select',"searchoptions": { 
      "value": ":All;Asia Pacific:Asia Pacific;Australia/NZ:Australia/NZ;Europe:Europe;Japan:Japan;Latin America:Latin America;North America:North America;CCEMA:CCEMA" 
     }} 
    ], 
    postData: {  
    },  
    height: 'auto',  
    autowidth: true,  
    rownumbers: true,  
    pager: '#pager',  
    viewrecords: true,  
    sortorder: "asc",  
    emptyrecords: "Empty records",  
    loadonce: true, 
    rowNum:20, 
    ignoreCase: true, 
    prmNames: { 
     nd: null 
    }, 
    loadComplete: function() { 
    }, 

    jsonReader : {  
     root: "rows",   
     repeatitems: false, 
     page:"page",   
     total: "total",   
     records: "records", 
     cell: "cell",   
     id: "id"  
     } 
    }); 

jQuery("#grid").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search: false, refresh:true}) 
    .navButtonAdd('#pager',{caption:"Export All",buttonicon:"ui-icon-document",onClickButton: function(){window.open(excelUrl,'_self');},position:"last"}); 
jQuery("#grid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn",ignoreCase: true }); 

我从筛选器中选择欧洲地区而不是网格应过滤记录欧洲地区的记录。 这工作正常。但现在的要求是,如果欧洲地区被选中,那么我应该在网格中显示包含欧洲地区和CCEMA的所有记录。这可能吗?如果有可能比如何做到这一点?

注意:我使用loadonce = true一次在网格中加载数据库中的所有记录。

回答

0

如果我理解你的问题正确,那么你可以尝试选择欧洲等组合价值“的欧洲,CCEMA:欧洲”;所以在服务器端,当您在下拉列表中选择欧洲时,您可能会收到“欧洲,CCEMA”作为搜索值。然后你可以用SQL“in”子句对这些值进行一些修改。

你也可以用比逗号其他字符(,)结合不同的值,但你必须设置相应的逻辑在服务器端。

试试看看是否有帮助

例如,

{name:'requestorRegion', index:'requestorRegion',sortable: true,width:65,editable:false, editrules:{required:true}, editoptions:{size:8, style: "height: 90%"}, stype:'select', edittype:'select',"searchoptions": { 
     "value": ":All;Asia Pacific:Asia Pacific;Australia/NZ:Australia/NZ;Europe,CCEMA:Europe;Japan:Japan;Latin America:Latin America;North America:North America;CCEMA:CCEMA" 
    }}