jqgrid filterToolbar不起作用 [英] jqgrid filterToolbar not working

查看:277
本文介绍了jqgrid filterToolbar不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我正在用这个来敲我的头,因为我在许多应用程序中都使用过jqgrid,并且类似的代码在其他情况下也能正常工作! 这是代码...

Well i am banging my head against the wall with this one because i have used jqgrid in many apps and similar code is working in every other case but this! Here is the code...

var pfct = $("#pfc_table");
pfct.jqGrid({
        url: 'costs',
        datatype: 'json',
        'postData': JSON.stringify(getConds()),
        mtype: 'POST',
        colNames:['Id','Name','Formula','Conditions'],
        colModel :[
          {name:'id', index:'id', width:40, search:true},
          {name:'name', index:'name', width:130, search:true},
          {
              name:'formula', index:'formula',width:310, search:true,
              formatter : function(value, options, rData){
                  return value.substring(value.indexOf('=')+1);
              }
          },
          {name:'conditionstr', index:'conditionstr', width:160,search:true}
        ],
        jsonReader: {
            repeatitems:false,
            root: function (r) { return r.data.rows; },
            page: function (r) { return r.data.currpage; },
            total: function (r) { return r.data.totalpages; },
            records: function (r) { return r.data.totalrecords; }
        },
        gridComplete: function() {
        },
        gridview: true,
        height: 'auto',
        autowidth: true,
        pager: '#pfc_pager',
        rowNum:25,
        viewrecords: true,
        loadonce: true,
        ignoreCase: true,
        multiselect: false,
        pagination: true
});
pfct.navGrid('#pfc_pager',{edit:false,add:false,del:false,search:false,refresh:false});
pfct.jqGrid('filterToolbar',{stringResult: true,searchOnEnter: false});

我发送的json数据有一些额外的属性,这些属性在colmodel中没有定义,但这在过去从来都不是问题.本地排序和分页效果很好,但过滤效果不佳! 对于记录,这就是数据的样子:

The json data i am sending have a few extra properties that are not defined in the colmodel but this has never been a problem in the past. Local sorting and paging works fine, but filtering does not! For the record this is what the data looks like:

{"data":{"totalpages":1,"currpage":1,"totalrecords":10,"rows":[{"name":"Test","id":18195,"level":0,"currency":"EUR","default":true,"formula":"f_18195()=110","ownerId":1,"categoryName":"Test cat","parentId":0,"rebate":0,"portDues":true,"modified":1310036286000,"conditionstr":"Condition 1, Condition 2"}],"userdata":null},"status":true,"responseError":null}

推荐答案

您的原始网格有一个问题.您在公式"列中使用自定义格式化程序:

Your original grid has one problem. You use custom formatter for the 'formula' column:

formatter : function(value, options, rData){
    return value.substring(value.indexOf('=')+1);
}

,因此数据"f_18195()=110"将显示为"100".在datatype: 'json' 没有 loadonce: true的情况下,此方法有效,但在loadonce: true的情况下,则错误.问题在于,本地保存在formula列中的数据将是"f_18195()=110",而不是"100".因此,在过滤数据期间,必须键入"f"或"f_18195()= 1"而不是"1"来过滤数据:

so the data "f_18195()=110" will be displayed as "100". The way works good in case of datatype: 'json' without loadonce: true, but works wrong in case of loadonce: true. The problem is that the data saved locally for the formula column will be "f_18195()=110" and not "100". So during filtering of the data one have to type "f" or "f_18195()=1" instead of "1" to filter the data:

如果将jsonmap用作功能,则可以解决此问题:

You can fix the problem if you would use jsonmap as function:

jsonmap: function (obj) {
    var f = obj.formula;
    return f.substring(f.indexOf('=')+1);
}

代替自定义格式化程序的用法公式"列.在这种情况下,值"100"将保存在本地,并且数据过滤将按预期进行:

instead of usage of usage of custom formatter for the 'formula' column. In the case the value "100" will be saved locally and the filtering of data works as expected:

此处中查看相应的演示.

这篇关于jqgrid filterToolbar不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆