2013-05-11 67 views
1

如何添加搜索运算符而不直接插入文件jquery.jqGrid.src.jsjqGrid添加自定义搜索运算符(ops对象)

例如:

ops: [ 
    {"name": "eq", "description": "equal", "operator": "="}, 
    {"name": "ne", "description": "not equal", "operator": "<>"}, 
    {"name": "lt", "description": "less", "operator": "<"}, 
    {"name": "the", "description": "less or equal", "operator": "<="}, 
    {"name": "gt", "description": "greater", "operator": ">"}, 
    {"name": "ge", "description": "greater or equal", "operator": "> ="}, 
    {"name": "bw", "description": "begins with", "operator": "LIKE"}, 
    {"name": "bn", "description": "does not begin with", "operator": "NOT LIKE"}, 
    {"name": "in", "description": "in", "operator": "IN"}, 
    {"name": "ni", "description": "not in", "operator": "NOT IN"}, 
    {"name": "ew", "description": "ends with", "operator": "LIKE"}, 
    {"name": "en", "description": "does not end with", "operator": "NOT LIKE"}, 
    {"name": "cn", "description": "contains", "operator": "LIKE"}, 
    {"name": "nc", "description": "Does not contain", "operator": "NOT LIKE"}, 
    {"name": "noo", "description": "is null", "operator": "IS NULL"}, 
    {"name": "nn", "description": "is not null", "operator": "IS NOT NULL"}, 
    {"name": "xx", "description": "xxx", "operator": "CUSTOM"} ] 

这种变化可以正常工作,但你可以与外部文件做呢?

回答

1

首先您应该明白,添加自定义搜索操作符并不遵循操作符的实现。我想你有服务器端实现的搜索。在扩展搜索操作的情况下大多是简单的。

内部结构ops将在下一个版本的jqGrid中更改。所以我建议你只需在​​内部修改<select>选项。查看相应代码示例的the answerthis onethis one。你的情况,你可以使用

afterRedraw: function() { 
    $(this).find("table.group td.operators>select.selectopts") 
     .append("<option value='xx'>xxx</option>"); 
} 

The demo使用上述​​并显示

enter image description here

的演示使用当地datatype,所以与操作的搜索没有原因的工作,但postData参数将被设置为对应于所选操作。