【问题标题】:reloading dataurl elements in jqGrid在 jqGrid 中重新加载 dataurl 元素
【发布时间】:2012-11-21 10:41:51
【问题描述】:

我有一个带有以下选项的简单网格:

jQuery("#mygrid").jqGrid({
   url: 'dataurl.htm',
   datatype: 'json',
   ajaxSelectOptions: { cache: false }
   ...
   colModel: [
    { name: 'foo', index: 'foo', width: 25, stype: 'select', searchoptions:{ sopt:       
     ['eq'], dataUrl: 'someurl.htm?columnName=foo'}}
    ]
});

但是,当我调用$("#mygrid").trigger("reloadGrid"); 时,它只从dataurl.htm 加载表的数据,但不会从some url.htm 链接加载foo 列的数据。

我在 SO 上阅读了几个类似的问题,建议使用ajaxSelectOptions: { cache: false },但这对我不起作用。

someurl.htm 返回<select> <option val=''>something</option></select>

【问题讨论】:

  • 您在哪里使用搜索:工具栏搜索或搜索对话框?
  • 我在工具栏中搜索

标签: javascript jquery jqgrid


【解决方案1】:

这是绝对正确的问题! jqGrid 目前的实现只有toggleToolbar 方法可以隐藏工具栏,但工具栏本身会被创建一次。因此工具栏的所有属性始终保持不变。

为了解决这个问题,我写了一个小的附加方法destroyFilterToolbar,这很简单:

$.jgrid.extend({
    destroyFilterToolbar: function () {
        "use strict";
        return this.each(function () {
            if (!this.ftoolbar) {
                return;
            }
            this.triggerToolbar = null;
            this.clearToolbar = null;
            this.toggleToolbar = null;
            this.ftoolbar = false;
            $(this.grid.hDiv).find("table thead tr.ui-search-toolbar").remove();
        });
    }
});

The demo 使用该方法。更改某些列的属性后,可以重新创建搜索工具栏。在下面的代码中,可以从搜索工具栏中更改某些文本的语言:

对应的代码如下:

$("#recreateSearchingToolbar").change(function () {
    var language = $(this).val();

    // destroy searching toolbar
    $grid.jqGrid("destroyFilterToolbar");

    // set some searching options
    $grid.jqGrid("setColProp", "closed",
        language === "de" ?
                {searchoptions: {value: ":Beliebig;true:Ja;false:Nein"}} :
                {searchoptions: {value: ":Any;true:Yes;false:No"}});
    $grid.jqGrid("setColProp", "ship_via",
        language === "de" ?
                {searchoptions: {value: ":Beliebig;FE:FedEx;TN:TNT;IN:Intim"}} :
                {searchoptions: {value: ":Any;FE:FedEx;TN:TNT;IN:Intim"}});

    // create new searching toolbar with nes options
    $grid.jqGrid("filterToolbar", {stringResult: true, defaultSearch: "cn"});
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 2011-09-11
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    相关资源
    最近更新 更多