【问题标题】:Filtering in jqgrid with remote data and formatting使用远程数据和格式化在 jqgrid 中进行过滤
【发布时间】:2012-11-07 17:41:11
【问题描述】:

我需要在不使用内置 UI 的情况下在 jqgrid 中本地过滤数据。我遵循了 Oleg 在帖子 jqGrid Filtering Records 中给出的答案。它对我的设置进行了一些更改,就像一个魅力。但是,我似乎无法让它适用于记录格式化的字段。 jqgrid 数据是远程的。

jqGrid Filtering Records 发布代码示例,因为这几乎就是我所拥有的:

$("#search").click(function() {
var searchFiler = $("#filter").val(), grid = $("#list"), f;

if (searchFiler.length === 0) {
    grid[0].p.search = false;
    $.extend(grid[0].p.postData,{filters:""});
}
f = {groupOp:"OR",rules:[]};
f.rules.push({field:"name",op:"cn",data:searchFiler});
f.rules.push({field:"note",op:"cn",data:searchFiler});
grid[0].p.search = true;
$.extend(grid[0].p.postData,{filters:JSON.stringify(f)});
grid.trigger("reloadGrid",[{page:1,current:true}]);
});

在我的例子中,字段“名称”在 jqgrid 中格式化:

{name:"name", index:"name", width:250, align:'left',
  formatter: function(cellvalue, options, rowObject)
{
  return rowObject.Data[0]['userName'];
}
 },
 ...
 jsonReader : {
        repeatitems:false,
         root: 'rows',
         userdata: 'rows'
      },
loadonce: true,      
viewrecords: true,
autowidth: true,
multiselect: false,
height: 500,    
rowNum: 999,
subGrid: true,

我们对后端进行一次查询,并将数据存储在“行”中,以便在子网格中显示。

非常感谢任何指针。

谢谢,

阿莎

【问题讨论】:

    标签: jquery jqgrid


    【解决方案1】:

    我认为您不需要在这种情况下使用自定义格式化程序。我想你可以使用jsonmap。可能jsonmap: "Data.0.userName" 确实需要你。或者,您可以使用jsonmap 作为函数(如herehere)。

    一般来说,您应该始终将unformattercustom formatter 一起定义。这可能是您当前问题的原因。

    【讨论】:

    • 非常感谢,奥列格。它就像一个魅力。我想我在这里从来不需要格式化程序。 jsonmap: "Data.0.userName" 有效。现在我不确定为什么我首先使用自定义格式化程序,因为我基本上只是在这里映射数据。你在这里给了我很多选择,所以下次我可以做出更好的决定。
    • 对于过滤是否可以使其不区分大小写。我尝试添加 'var searchFiler = $("#filter").val().toLowerCase(), f',但这会错过我在 'name' 字段中有类似 'Asha' 的情况。
    • 没关系,将 ignoreCase: true 添加到您在 Case insensitive wildcard filter with filterToolbar 中提到的 jqgrid 中。那行得通。再次感谢。
    • @Asha:你可以只包含ignoreCase: true jqGrid 选项。
    猜你喜欢
    • 2012-04-24
    • 2016-09-12
    • 2013-02-13
    • 2011-10-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 2017-12-05
    • 2020-04-28
    相关资源
    最近更新 更多