在jqGrid中重新加载dataurl元素

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

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返回 something

这是绝对正确的问题! 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(); }); } }); 

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

在此处输入图像描述

相应的代码如下:

 $("#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"}); });