jqGrid colmodel在loadComplete中更改

经过3个小时的谷歌搜索,我请求你的帮助。

我在页面上有一个jqGrid。

网格的重要选项:

$("#listU05").jqGrid({ url:'u05json.json', datatype: 'json', mtype: 'POST', colModel :[ {name:'Thema', index:'Thema', width:55}, .... loadComplete: function(data) { jQuery("#listU05").jqGrid.setColProp('Thema', { stype: 'select', searchoptions: { value:"a:a;b:b" } } ); 

加载数据后,我的网格上有[Loading …]矩形,对代码没有任何反应。 我在调试器中看到代码是活动的但我在colModel中没有任何可见的结果,我有矩形。

问题是什么?

非常感谢你的帮助。

更新 :当前使用的代码仍然不起作用如下

                $(document).ready(function(){ var getUniqueNames = function(grid, columnName, data, dataIndex) { // var data = grid.getGridParam('data'); var uniqueTexts = [], text, textsMap = {}, i; for (i = 0; i < data.rows.length; i++) { text = data.rows[i].cell[dataIndex]; if (text !== undefined && textsMap[text] === undefined) { textsMap[text] = true; uniqueTexts.push(text); } } return uniqueTexts; } buildSearchSelect = function(uniqueNames) { var values=":All"; $.each (uniqueNames, function() { values += ";" + this + ":" + this; }); return values; } setSearchSelect = function(grid, columnName, data, dataIndex) { grid.setColProp(columnName, { stype: 'select', searchoptions: { value:'a:a', sopt:['eq'] } }); } $("#listU05").jqGrid({ url:'u05json.json', datatype: 'json', mtype: 'POST', colNames:[ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' ], colModel :[ {name:'Thema', index:'u_05_01.Thema', width:55}, {name:'u_05_01.SubThema', index:'u_05_01.SubThema', width:55, stype: 'select', searchoptions:{ value:":\*All${subThemaOptions}" }}, {name:'u_05_01.status1', index:'u_05_01.status1', width:55, stype: 'select', searchoptions:{ value:":\*All${status1Options}" }}, {name:'u_05_01.wie', index:'u_05_01.wie', width:55, stype: 'select', searchoptions:{ value:":\*All${wieOptions}" }}, {name:'u_05_01.KW', index:'u_05_01.KW', width:55, stype: 'select', searchoptions:{ value:":\*All${kwOptions}" }}, {name:'Jahr', index:'u_05_01.Jahr', width:55, stype: 'select', searchoptions:{ value:":\*All${jahrOptions}" }}, {name:'u_05_01.kampagne', index:'u_05_01.kampagne', width:55, stype: 'select', searchoptions:{ value:":\*All${kampagneOptions}" }}, {name:'u_05_01.ergebnis', index:'u_05_01.ergebnis', width:55, stype: 'select', searchoptions:{ value:":\*All${ergebnisOptions}" }}, {name:'u_05_01.B1', index:'u_05_01.B1', width:55, stype: 'select', searchoptions:{ value:":\*All${b1Options}" }}, {name:'u_05_01.B2', index:'u_05_01.B2', width:55, stype: 'select', searchoptions:{ value:":\*All${b2Options}" }}, {name:'u_03.personal', index:'u_03.personal', width:55, stype: 'select', searchoptions:{ value:":\*All${personalOptions}" }}, {name:'u_03.qualifikation', index:'u_03.qualifikation', width:55, stype: 'select', searchoptions:{ value:":\*All${qualifikationOptions}" }}, {name:'u_03.iv', index:'u_03.iv', width:55, stype: 'select', searchoptions:{ value:":\*All${ivOptions}" }}, {name:'u_05_01.objekt', index:'u_05_01.objekt', width:55, stype: 'select', searchoptions:{ value:":\*All${objektOptions}" }}, {name:'u_05_01.NR', index:'u_05_01.NR', width:55, stype: 'select', searchoptions:{ value:":\*All${nrOptions}" }}, {name:'u_05_01.ObjektArt', index:'u_05_01.ObjektArt', width:55, stype: 'select', searchoptions:{ value:":\*All${objektArtOptions}" }}, {name:'u_06.vorname', index:'u_06.vorname', width:55, stype: 'select', searchoptions:{ value:":\*All${vornameOptions}" }}, {name:'u_06.name', index:'u_06.name', width:55, stype: 'select', searchoptions:{ value:":\*All${nameOptions}" }}, {name:'u_05_01.Z1', index:'u_05_01.Z1', width:55, stype: 'select', searchoptions:{ value:":\*All${z1Options}" }}, {name:'u_05_01.Z2', index:'u_05_01.Z2', width:55, stype: 'select', searchoptions:{ value:":\*All${z2Options}" }}, {name:'u_05_01.Z3', index:'u_05_01.Z3', width:55, stype: 'select', searchoptions:{ value:":\*All${z3Options}" }}, {name:'u_05_01.Z4', index:'u_05_01.Z4', width:55, stype: 'select', searchoptions:{ value:":\*All${z4Options}" }}, {name:'u_05_01.team', index:'u_05_01.team', width:55, stype: 'select', searchoptions:{ value:":\*All${teamOptions}" }} ], pager: '#pager', rowNum:100, rowList:[10,50,100], sortname: 'u_05_01.Thema', sortorder: 'asc', viewrecords: true, gridview: true, height: "400px", caption: '', loadComplete: function(data) { $(this).jqGrid('setColProp', 'Thema', { stype: 'select', searchoptions: { value:"a:a" } }); } }); jQuery("#listU05").jqGrid('navGrid','#pager',{del:false,add:false,edit:false,search:false}); jQuery("#listU05").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false}); // Loop for each select element on the page. $("select").each(function() { // Keep track of the selected option. var selectedValue = $(this).val(); // Sort all the options by text. I could easily sort these by val. $(this).html($("option", $(this)).sort(function(a, b) { return a.text == b.text ? 0 : a.text < b.text ? -1 : 1 })); // Select one option. $(this).val(selectedValue); }); });    
/


不会消失的“正在加载…”通常意味着在填充网格或执行某些回调函数(如loadComplete期间发生exception。 在你的情况下,错误是你使用jQuery("#listU05").jqGrid.setColProp而不是jQuery("#listU05").setColPropjQuery("#listU05").jqGrid('setColProp', ...

您可以使用loadComplete的代码

 loadComplete: function(data) { $(this).jqGrid('setColProp', 'Thema', { stype: 'select', searchoptions: { value:"a:a;b:b" } }); } 

我建议您另外考虑使用beforeProcessing进行此类操作。 在设置colModel搜索属性的情况下,它并不重要,但如果你想使用formatter:’select’并从服务器加载editoptions.value ,那么beforeProcessing使用就是完全正确的地方。 尚未处理从服务器返回的数据。 因此,您可以更改editoptions的 value属性,并且在当前数据处理期间 , editoptions的value属性将由'select'格式化程序使用。