我有一个带有以下选项的简单网格:
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
加载表的数据但它不会加载 foo
的数据来自 some url.htm
的专栏关联。
我已经在 SO 上阅读了几个这样的问题,建议有 ajaxSelectOptions: { cache: false }
但这对我不起作用。
someurl.htm
返回 <select> <option val=''>something</option></select>
最佳答案
这个问题绝对正确!当前的 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"});
});
关于javascript - 在 jqGrid 中重新加载 dataurl 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13692177/