禁用整个jqGrid [英] Disable entire jqGrid

查看:109
本文介绍了禁用整个jqGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找有关如何禁用jqGrid的方法,并且发现了一些方法:

I have been looking for methods on how to disable a jqGrid and I found some:

  1. 使用BlockUI插件: http://jquery.malsup.com/block/
  2. 使用jqGrid选项:loadui并将其设置为阻止"

第一个选项是一个很好的解决方案(我还没有尝试过),也许更清晰了,但是如果可以的话,我想通过设置对象属性来避免使用插件,所以我尝试第二个选项,但是它是对我不起作用,jqGrid继续启用.

First option is a great solution (I have not tried yet) and it is clearer maybe but I want to avoid using plugins if I can whenever I can do it by setting object properties so I am trying the second option but it is not working for me, jqGrid continues enabled.

我在asp.net mvc 4视图中的jqgrid:

My jqgrid in my asp.net mvc 4 view:

<div id="jqGrid">
    @Html.Partial("../Grids/_PartialGrid")
</div>

和_PartialGrid:

and _PartialGrid:

<table id="_compGrid" cellpadding="0" cellspacing="0">
</table>
<div id="_compPager" style="text-align: center;">
</div>

因此,在视图中的脚本部分中,我将在以下位置对准备好的文档执行以下操作,具体取决于模型中属性的状态(如果id> 0则禁用它,否则在页面重新加载时启用它):

so in the view, in script section I perform below on document ready and depending on the status of a property in my model (I disable it if id>0, otherwise I enable it on page reload):

@section scripts
{
    @Content.Script("/Grids/CompGrid.js", Url) // Content is a helper javascript loader (see end of this post)
}

<script type="text/javascript">
$(document).ready(function () {

    showGrid();
    var disableCompGrid = @Html.Raw(Json.Encode(Model.ItemCompViewModel));
    setStatusCompGrid(disableCompGrid.id > 0);

}
</script>

CompGrid.js是:

CompGrid.js is:

function showGrid() {
    $('#_compGrid').jqGrid({
        caption: paramFromView.Caption,
        colNames: ....
}

function setStatusCompGrid(disabled) {
           $('#_compGrid').jqGrid({
                loadui: 'block',
                loadtext: 'Processing...'
           });
}

在上面的代码中,我也尝试将禁用的参数传递给showGrid函数,并分别将变量设置为'block'或'enable'取决于是真还是假,然后使用该变量设置loadui属性但它不起作用.

In the code above, also I have tried to pass as parameter disabled to showGrid function and depending on if it is true or false to set a variable to 'block' or 'enable' respectively and then setting loadui property with this variable but it is not working.

Content.cshtml:

Content.cshtml:

@using System.Web.Mvc;

@helper Script(string scriptName, UrlHelper url)
{
    <script src="@url.Content(string.Format("~/Scripts/{0}", scriptName))" type="text/javascript"></script>
}

有什么想法吗?

推荐答案

重要的是要理解,调用$('#_compGrid').jqGrid({...}); 初始空的<table id="_compGrid"></table>元素转换为相对复杂的下潜和表结构.因此,您只能一次进行一次此类呼叫.这样的调用创建并初始化网格.换句话说,函数showGrid具有错误的名称.该函数只能调用一次 .第二次调用将测试该网格已经存在,并且将不执行任何操作.如果需要更改现有网格的某些参数,可以使用setGridParam方法.

It's important to understand that the call $('#_compGrid').jqGrid({...}); converts initial empty <table id="_compGrid"></table> element to relatively complex structure of dives and tables. So you can do such call only once. Such call creates and initialize the grid. In other words the function showGrid has bad name. The function can be called only once. The second call of it will test that the grid already exist and it will do nothing. If you need to change some parameters of existing grid you can use setGridParam method.

在这种情况下,您可以绝对使用另一种解决方案来阻塞网格.调用$('#_compGrid').jqGrid({...});之后,初始表的DOM元素将获得一些expandos-新的属性或方法.例如,$('#_compGrid')[0]将包含grid属性,该属性包含beginReqendReq方法.因此,您可以首先创建网格(在showGrid函数中),并在使用的选项列表中包括选项loadui: 'block'loadtext: 'Processing...'.然后,如果您以后需要屏蔽网格,则可以使用

In the case you can use absolutely another solution to block the grid. After the call $('#_compGrid').jqGrid({...}); the DOM element of the initial table get some expandos - new property or method. For example $('#_compGrid')[0] will contains grid property which contains beginReq and endReq methods. So you can first create the grid (in the showGrid function) and include options loadui: 'block' and loadtext: 'Processing...' in the list of options which you use. Then if you need to block the grid later you can use

$('#_compGrid')[0].grid.beginReq();

和代码

$('#_compGrid')[0].grid.endReq();

以消除阻塞.请参见演示进行演示.另外,您可以显示由jqGrid手动创建的叠加层,如我在答案中所述.代码将非常简单:

to remove blocking. See the demo which demonstrates this. Alternatively you can show overlays created by jqGrid manually like I described in the answer. The code will be simple enough:

var gridId = "_compGrid"; // id of the grid
...
$("#lui_" + gridId).show();
$("#load_" + gridId).text("Processing...").show();

显示叠加层和

$("#lui_" + gridId).hide();
$("#load_" + gridId).hide();

隐藏叠加层.请参见另一个演示,其工作原理与第一个演示完全相同.

to hide the overlay. See another demo which works exactly like the first one.

这篇关于禁用整个jqGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆