jqGrid显示默认的“正在加载"表格更新/自定义更新时的提示信息 [英] jqGrid display default "loading" message when updating a table / on custom update
问题描述
在某些情况下,我需要根据用户选择的某些搜索条件来更新jqgrid.我可以获取要更新的数据,但是我希望在获取新数据时显示加载消息.有人可以让我知道如何使它工作吗?
I have a case where I need to update a jqgrid based on some search criteria which the user selects. I can get the data to update , but I would want the loading message to show while the new data is being fetched. Can someone please let me know how to get that working ?
遵循当前代码
var ob_gridContents = $.ajax( {
url : '/DisplayObAnalysisResults.action?getCustomAnalysisResults',
data : "portfolioCategory="+ $('#portfolioCategory').val()
+"&subPortfolioCategory="+ $('#subPortfolioCategory').val()
+ "&subportfolio=" + $('#subportfolio').val(),
async : false
}).responseText;
var ob_Grid = jQuery('#OBGrid')[0];
var ob_GridJsonContents = eval('(' + ob_gridContents + ')');
$('#ob_Grid').trigger("reloadGrid");
ob_Grid.addJSONData(ob_GridJsonContents);
ob_Grid = null;
ob_GridJsonContents = null;
}
推荐答案
如果我正确理解了您的意愿,那么我建议您使用jQuery blockUI插件(
If I correct understand what you will, I can recommend you to use jQuery blockUI plugin (http://malsup.com/jquery/block/). Then you don’t need more to use "async : false" parameter of $.ajax function and do something like following:
var WaitMsg = function () {
jQuery('#main').block({ message: '<h1>Die Daten werden vom Server geladen...</h1>' });
};
var StopWaiting = function () {
jQuery('#main').unblock();
};
WaitMsg();
$.ajax({url : '/DisplayObAnalysisResults.action?getCustomAnalysisResults',
data: jQuery.param({portfolioCategory: $('#portfolioCategory').val(),
subPortfolioCategory: $('#subPortfolioCategory').val(),
subportfolio: $('#subportfolio').val()}),
complete: function (data, status) {
if (status === "success" || status === "notmodified") {
var ob_GridJsonContents = jQuery.parseJSON(data.responseText);
...
}
StopWaiting();
},
error: function (xhr, st, err) {
// display error information
StopWaiting();
}
});
我建议您不要以类似的方式构建参数
I recommend you don’t build parameters with the way like
"portfolioCategory =" + $('#portfolioCategory').val() +& subPortfolioCategory =" + $('#subPortfolioCategory').val() +& subportfolio =" + $('#subportfolio').val()
"portfolioCategory="+ $('#portfolioCategory').val() +"&subPortfolioCategory="+ $('#subPortfolioCategory').val() + "&subportfolio=" + $('#subportfolio').val()
如果 .val()返回的数据具有某些特殊字符,则可能会遇到编码问题.在这种情况下,您可以使用JavaScript函数 encodeURIComponent (例如 encodeURIComponent($('#portfolioCategory').val()))
或 jQuery.param 函数(如果您构造类似 p1 = val1& p2 = val2& ... pN = valN 的字符串).
最好的问候
奥列格(Oleg)
because you can receive encoding problems, if data returned by .val() have some special characters. You could use JavaScript function encodeURIComponent in such cases (like encodeURIComponent($('#portfolioCategory').val()))
or jQuery.param function if you construct a string like p1=val1&p2=val2&...pN=valN.
Best regards
Oleg
这篇关于jqGrid显示默认的“正在加载"表格更新/自定义更新时的提示信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!