0

私は jqgrid を持っています:

    jQuery("#list").jqGrid( {
            url : 'ajax/get',
            datatype : 'json',
            mtype : 'POST',
            colNames : [
                'Date',
                'ID'
            ],
            colModel : [{
                    name : 'date',
                    index : 'date',
                    width : 60,
              align : 'center',
                    searchoptions:{sopt:['gt', 'lt']}
                },{
                    name : 'id',
                    index : 'id',
                    width : 40,
              align : 'center',
                    searchoptions:{sopt:['eq']}
                }]
   //.......
        });

「日付」列に「odata」オプションを設定する方法はありますか。現在、「大きい」と「小さい」が表示されています。「から」と「から」が必要です。

私はこれを試します:

colModel : [{
                    name : 'date',
                    index : 'date',
                    width : 60,
                    align : 'center',
                    searchoptions:{sopt:['gt', 'lt'], odata:['from', 'to']}
                }

機能していませんが、「大きい」と「小さい」が表示されます。これを試しました:

$(document).ready(function(){
  $.jgrid.search = {
    odata : ['equal','not equal', 'to', 'less or equal','from','greater or equal', 'begins with','does not begin with','is in','is not in','ends with','does not end with','contains','does not contain']
  };
  $.extend($.jgrid.search);
});

すべての列で「大きい」を「から」に、「小さい」を「に」に置き換えますが、必要なのは「日付」列だけです。それを行う方法はありますか?

ありがとう。

4

3 に答える 3

1

同様の問題があり、jqGridソースコードの一部を編集することで解決しました。

ops 配列に演算子を追加しました。(バージョン 4.4.0 では 6130 行でした。)

ops : [
    {"name": "eq", "description": "equal", "operator":"="},
    {"name": "ne", "description": "not equal", "operator":"<>"},
    {"name": "lt", "description": "less", "operator":"<"},
    {"name": "le", "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": "nu", "description": "is null", "operator":"IS NULL"},
    {"name": "nn", "description": "is not null", "operator":"IS NOT NULL"},
    {"name": "to", "description": "to", "operator":"<"},
    {"name": "fr", "description": "from", "operator":">"}
    ],
numopts :  
    ['eq','ne','lt','le','gt','ge','nu','nn','in','ni'],
stropts :
    ['eq','ne','bw','bn','ew','en','cn','nc','nu','nn','in', 'ni','to','fr'],

これらの新しいオプションを、日付列の仕様の sopt パラメータで使用します。(検索結果の実装によっては、これらの演算子を変換するためにバックエンドを調整する必要がある場合もあります。)

{name:'mydatefield', searchoptions: {sopt:['to', 'fr']}}

お役に立てれば。

于 2012-11-30T15:37:54.107 に答える
0

jqGrid で検索を使用するには、おそらくnavGrid関数を呼び出して、検索ボタンでナビゲーターを追加します。この関数navGridには、6 番目のパラメーターとしてオブジェクト ( http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator#definition$.jgrid.searchを参照) があり、これを使用して、包含パラメーターからデフォルトのパラメーターを上書きできodataます。したがって、次のようなことができます

jQuery("#list").jqGrid('navGrid','#pager',{search:true},{},{},{},
                {odata:['equal','not equal', 'to', 'less or equal','from',
                        'greater or equal', 'begins with','does not begin with',
                        'is in','is not in','ends with','does not end with',
                        'contains','does not contain']});
于 2010-07-26T14:50:38.007 に答える