自定义jqgrid过滤器逻辑

时间:2015-10-20 05:48:21

标签: jquery jqgrid

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

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 在网格中一次性加载数据库中的所有记录。

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,那么你可以尝试将选项欧洲的价值结合起来,比如“欧洲,CCEMA:欧洲;”因此,在服务器端,当您在下拉列表中选择欧洲时,您可能会收到“Europe,CCEMA”作为搜索值。然后,您可以将这些值与SQL“in”子句一起使用,只需稍加修改。

您还可以使用逗号(,)以外的字符组合不同的值,但您必须在服务器端相应地设置逻辑。

尝试一下,看看是否有帮助

e.g。

    {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"
   }}
相关问题