当匹配规则为“any”且第一个查询具有数据Url时,jqGrid搜索无法正常工作

时间:2011-02-18 19:35:12

标签: jqgrid

方案:
使用" stype:'选择'"对于'客户'搜索弹出窗口中的列。

此列的dataUrl返回"<select><option value='F'>F</option><option value='O'>O</option></select>"

打开搜索弹出窗口。

搜索条件的第一行:&#39;客户不等于F&#39;

第二行搜索条件:&#39; 金额不等于300&#39;

匹配类型:&#39;任何&#39;

点击查找。

我希望这两个记录的客户类型为==&#39; F&#39;出现,但两者都没有。看起来匹配类型仍然是&#39; AND&#39;而不是&#39; OR&#39;。

$(function() {
    var mydata = [              
            {id:"1", name:"test",       amount:"200"},
            {id:"2", name:"test2",      amount:"300"},
            {id:"3", name:"F",          amount:"400"},
            {id:"4", name:"test4",      amount:"200"},
            {id:"5", name:"test5",      amount:"300"},
            {id:"6", name:"test6",      amount:"400"},
            {id:"7", name:"test7",      amount:"200"},
            {id:"8", name:"test8",      amount:"300"},
            {id:"9", name:"test9",      amount:"400"},
            {id:"10",name:"test10",     amount:"500"},
            {id:"11",name:"F",          amount:"500"},
            {id:"12",name:"test11",     amount:"500"},
            {id:"13", name:"test",      amount:"200"},
            {id:"14", name:"O",         amount:"200"}
    ];
    jQuery("#list").jqGrid({            
        datatype: "local",
        data: mydata,
        width: 700,
        colNames:['Inv No','Client', 'Amount'],
        colModel:[
            {name:'id',index:'id', width:65, sorttype:'int', searchoptions:{sopt:['eq','ne','lt','le','gt','ge']}},
            {name:'name',index:'name', width:100, searchoptions:{dataUrl:'/api/domains/producttypedomain'}},
            {name:'amount',index:'amount', sorttype:'int', width:80, align:"right"}
        ],
        rowNum:100, 
        pager: '#pager',            
        height:'auto',
        viewrecords: true,
        rownumbers: true,
        gridview : true,            
        caption:"Advanced Search Example"
    });
    jQuery("#list").jqGrid('navGrid','#pager',
    {
        edit:false,add:false,del:false,search:true,refresh:true
    },
    {}, // edit options
    {}, // add options
    {}, //del options
    {multipleSearch:true, overlay:false,  recreateFilter:true} // search options
    );
});

1 个答案:

答案 0 :(得分:1)

我验证了您的示例,我发现您在jqGrid中发现了一个错误。所以给我+1给你。

顺便说一下,新版本的多版本插件中仍然存在相同的bug,现在处于alpha阶段(有关详细信息,请参阅here)。如果试图对两个“不相等”操作进行OR(任何)操作,则可以再现该错误。 “不相等”的实现有一个错误。

在jqGrid的当前版本(带有bug)中,搜索/过滤跟随执行语句,如

!(parseInt(this.amount,10) == parseInt(200,10)) && !(parseInt(this.amount,10) == parseInt(500,10))

如果是操作((amount<>200)||(amount<>500))。这是错误的。在当前版本的jqGrid中,“不相等”的实现是错误的。

我在jqGrid的源代码中解决了以下问题:

1)我添加了定义为

的新函数notEquals
this.notEquals=function(f,v,t){
    return self._compareValues(self.equals,f,v,"!==",t);
};

并在this.equals之后插入(见here)。

2)我修改了

中grid.base.js的line 1359
'ne':function(queryObj) {return queryObj.not().equals;},

'ne':function(queryObj) {return queryObj.notEquals;},

修复后,搜索工作正常。您可以看到结果here(您的原始版本可以测试here

下次我将在the trirand forum发布我的建议,我希望Tony Tomov(jqGrid的开发人员)将在jqGrid中实现修复。

更新:我承诺如何将the bug report与我的建议一起发布以解决问题。

更新2 :该错误已在GitHub的当前开发人员版本中修复。你可以看到结果here使用新修复版本,我的回答中提出了更多更改。您可以看到新的多选界面here