【问题标题】:Jqgrid search option for local datatype not working本地数据类型的 Jqgrid 搜索选项不起作用
【发布时间】:2014-01-02 18:36:36
【问题描述】:

我想为我的 jqgrid 表添加搜索选项,

$('#jqgrid').jqGrid({
    datatype: 'local',
    data: mydata,
    caption: 'Titlepage Parameters',
    gridview: true,
    height: 'auto',
    colNames: ['title', 'color', 'fontsize'],
    colModel: [
        {name: 'config.titlepage.title' },
        {name: 'config.titlepage.color' },
        {name: 'config.titlepage.fontsize' },
    ],
    pager: '#pageGrid'
    localReader: {
        id: "_id.$oid"
    }
});
$('#jqgrid').jqGrid('navGrid', "#pageGrid",
    { search: true, edit: false, add: false, del: false, refresh: false }, {}, {},
    { recreateFilter: true, overlay: true, multipleSearch: true, multipleGroup: true});

我得到了搜索选项,但是当我输入搜索字符串并单击过滤器按钮时,搜索正在发生。

请帮帮我,我需要添加任何库文件来执行此搜索过滤器吗?

【问题讨论】:

  • 您在colModellocalReader 中为name 使用了非常奇特的值。您能否包括一些您使用的测试数据(mydata 的值)?
  • 嗨 Oleg,这是 mydata 值,var mydata = [ { "_id": {"$oid": "50a3f962b7718da1a3090fa9"}, "config": { "titlepage": { "title" : "我的第一个标题", "color": true, "fontsize": "42/44" } } } ];

标签: javascript ajax jquery jqgrid


【解决方案1】:

我不确定您在搜索时遇到了哪些问题。唯一明显的错误是:您在navGrid 列表中跳过了一个{}。您当前的navGrid 选项将删除选项设置为搜索选项。正确的选项将是

$('#jqgrid').jqGrid('navGrid', "#pageGrid",
    { search: true, edit: false, add: false, del: false, refresh: false }, {}, {}, {},
    { recreateFilter: true, overlay: true, multipleSearch: true, multipleGroup: true});

此外,您可以考虑在网格中添加ignoreCase: true 选项以使搜索不区分大小写。 The demo 似乎工作正常。

可用于读取相同数据的另一个选项:使用datatype: 'jsonstring'。在这种情况下,您可以使用jsonmap 并选择更具可读性的name 属性。如果网格的内部data 将仅包含您需要的数据。 The demo 演示了这种方法。它使用以下代码

var mydata = [
        {
          "_id": {"$oid": "50a3f962b7718da1a3090fa9"},
          "config": { "titlepage": { "title": "My First Title", "color": true,
                                     "fontsize": "42/44" } } }
    ];

$('#jqgrid').jqGrid({
    datatype: 'jsonstring',
    datastr: mydata,
    caption: 'Titlepage Parameters',
    gridview: true,
    height: 'auto',
    colModel: [
        {name: 'title',    jsonmap: "config.titlepage.title" },
        {name: 'color',    jsonmap: "config.titlepage.color" },
        {name: 'fontsize', jsonmap: "config.titlepage.fontsize" },
    ],
    pager: '#pageGrid',
    jsonReader: {
        repeatitems: false,
        id: "_id.$oid"
    }
});
$('#jqgrid').jqGrid('navGrid', "#pageGrid",
    { search: true, edit: false, add: false, del: false, refresh: false }, {}, {}, {},
    { recreateFilter: true, overlay: true, multipleSearch: true, multipleGroup: true});

无论如何,我认为在两个演示中搜索都没有任何问题。

【讨论】:

  • 谢谢奥列格,它对我有用。我已经删除了本地数据类型并使用了 jsonString。现在它工作正常。
  • 嗨 Oleg,有没有机会在搜索过滤器中将“包含”设置为默认值而不是“相等”?
  • @DeepVeen:有很多方法可以做到这一点。例如,您可以指定搜索选项的sopt 参数(在与multipleGroup: true 相同的级别上)。或者,您可以使用cmTemplate,如cmTemplate: {searchoptions: {sopt: ['cn', 'nc', 'eq', 'ne', 'bw', 'bn', 'ew', 'en', 'nu', 'nn', 'in', 'ni']}}。重要的是数组中的第一个元素。应该是"cn"。见the demo
  • @DeepVeen:不客气!我建议你也使用filterToolbar。可以同时使用过滤器工具栏和高级搜索。用户可以使用更直观的过滤工具栏进行简单过滤,也可以使用高级搜索对话框进行更复杂的过滤。
  • 我只想从我的搜索框中删除添加子组按钮。是否有可能以及如何做到这一点?
猜你喜欢
  • 2014-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-14
  • 2014-11-29
  • 2011-03-11
  • 2013-05-24
相关资源
最近更新 更多