在加载Jqgrid之前和加载网格之后我应该在哪里使用方法来阻止屏幕?

ume*_*mer 5 javascript jquery jqgrid

我在java脚本中编写了一个阻止屏幕并取消阻止屏幕的功能.阻止屏幕意味着它阻止屏幕,因此用户无法点击任何内容(屏幕上出现加载程序图标).

UIBlocker有两种方法.

1. UIBlocker.blockScreen()   // It blocks the screen.
2. UIBlocker.unblockScreen()  // It unblocks the screen.
Run Code Online (Sandbox Code Playgroud)

现在,我需要在加载JQGrid时阻止屏幕.我想问一下我应该在哪里使用UIBlocker.blockScreen()UIBlocker.unblockScreen().

根据我的调查结果,UIBlocker.blockScreen应该使用beforeRequest事件,因为它要求数据之前触发.但是还有一些其他事件在加载之前就像beforeProcessing,loadBeforeSend一样触发.所以我仍然对此感到困惑.

第二件事是我应该在哪里使用unblockScreen.在loadComplete中还是在gridComplete中

在这里,我找到了jqgrid的执行顺序,

beforeRequest
loadBeforeSend
serializeGridData
loadError (if a error from the request occur - the event from steps 5 till 7 do not execute. If there is no error the event 4. does not execute and we continue to with the step 5.)
beforeProcessing
gridComplete
loadComplete
Run Code Online (Sandbox Code Playgroud)

现在建议我,我应该在哪里使用BlockScreenunblockScreen

Ole*_*leg 2

您可以考虑首先使用 loadui: "block" 选项。这是在从服务器加载数据期间阻止网格的标准方法。它不会阻塞整个屏幕(网络浏览器)。

如果上述方式不是您所需要的,那么您可以实施替代阻塞。该解决方案将取决于 jqGrid 的版本以及您使用的 jqGrid 的分支(免费 jqGrid、商业Guriddo jqGrid JS或版本 <=4.7 的旧 jqGrid )。您写道您使用的是复古版本4.4.4。如果您没有那么多可能性,推荐的方法是使用以下选项/回调:

loadui: "disable",  // remove the standard grid blocking
loadBeforeSend: function () {
    UIBlocker.blockScreen(); // block the grid/screen
    return true;    // allow request to the server
},
beforeProcessing: function () {
    UIBlocker.unblockScreen(); // unblock the grid/screen
    return true;    // process the server response
},
loadError: function (jqXHR, textStatus, errorThrown) {
    UIBlocker.unblockScreen(); // unblock the grid/screen

    // display the eror message in some way
    alert("HTTP status code: " + jqXHR.status + "\n" +
        "textStatus: " + textStatus + "\n" +
        "errorThrown: " + errorThrown);
}
Run Code Online (Sandbox Code Playgroud)

我提醒你,4.4.4版本确实是3.5年前发布的复古版本。您应该考虑将其升级到免费 jqGrid的当前版本(4.13.4)。它是 jqGrid 的分支,是我在将主分支商业化并将其重命名为 Guriddo jqGrid JS 后开发的(请参阅旧帖子价格表)。免费 jqGrid 可以在与您当前使用的旧版本 4.4.4 相同的许可协议下免费使用。

如果您要使用新版本的 jqGrid 那么推荐的方法是覆盖progressBarjqGrid 使用的方法

$.jgrid.extend({
    progressBar: function (options) {
        if (options.method === "show") {
            //alert("start blocking");
            UIBlocker.blockScreen();
        } else {
            //alert("stop blocking");
            UIBlocker.unblockScreen();
        }
    }
});
Run Code Online (Sandbox Code Playgroud)