2013-05-11 75 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參數將被設置爲對應於所選操作。