jqGrid的需要编辑的字段上添加对话框,但不能编辑对话框 [英] jqGrid need a field editable on Add dialog but not Edit dialog

查看:622
本文介绍了jqGrid的需要编辑的字段上添加对话框,但不能编辑对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的ASP.Net MVC应用程序中使用的jqGrid,并有一些列皆为中添加对话框而不是编辑对话框编辑的要求。显然,要做到这一点的办法是对特定输入域使用beforeShowForm JavaScript事件,并设置属性。

到目前为止,我不能设法得到beforeShowForm事件触发。下面是我的另一个发现了一个例子<一个href=\"http://stackoverflow.com/questions/1987881/how-to-have-different-edit-options-for-add-edit-forms-in-jqgrid\">SO问题但到目前为止,我还没有设法得到它的工作。有一些诀窍,我失踪?我使用的是最新版本3.8的jqGrid的。

控制器:

  [授权]
 公众的ActionResult指数()
 {
      VAR gridModel =新MyGridModel();
      SetUpGrid(gridModel.MyGrid);
      返回查看(gridModel);
 } 私人无效SetUpGrid(jqGrid的网格)
 {
        grid.DataUrl = Url.Action(GridDataRequested);
        grid.EditUrl = Url.Action(EditRows);
        grid.ToolBarSettings.ShowSearchToolBar = FALSE;        grid.ToolBarSettings.ShowEditButton = TRUE;
        grid.ToolBarSettings.ShowAddButton = TRUE;
        grid.ToolBarSettings.ShowDeleteButton = TRUE;
        grid.ToolBarSettings.ShowRefreshButton = TRUE;
        grid.EditDialogSettings.CloseAfterEditing = TRUE;
        grid.AddDialogSettings.CloseAfterAdding = TRUE;        grid.EditDialogSettings.Modal = FALSE;
        grid.EditDialogSettings.Width = 500;
        grid.EditDialogSettings.Height = 300;        grid.ClientSideEvents.GridInitialized =initGrid;
 }

型号:

 公共类MyGridModel
{
    公众的jqGrid MyGrid {搞定;组; }    公共MyGridModel()
    {
      MyGrid =新的jqGrid
      {
        列=新的List&LT; JQGridColumn&GT;()
        {
            新JQGridColumn {数据字段=ID,
                               的PrimaryKey = TRUE,
                               可见=假,
                               可编辑= FALSE},
            新JQGridColumn {数据字段=用户名,
                               可编辑= TRUE,
                               EditFieldAttributes =新的List&LT; JQGridEditFieldAttribute&GT;()
                               {
                                     新JQGridEditFieldAttribute(){名称=只读,值=真},
                                     新JQGridEditFieldAttribute(){名称=已禁用,值=真}
                                },
                                宽度= 100},
            新JQGridColumn {数据字段=域,
                               可编辑= TRUE,
                               EditFieldAttributes =新的List&LT; JQGridEditFieldAttribute&GT;()
                               {
                                    新JQGridEditFieldAttribute(){名称=只读,值=真},
                                    新JQGridEditFieldAttribute(){名称=已禁用,值=真}
                                },
                                宽度= 100}
              }
          }
     }
}

查看:

 函数initGrid(){  jQuery的(#myGrid)。的jqGrid('navGrid','#myGrid-寻呼机',
            {} //选项
            {//编辑选项
                beforeShowForm:功能(FRM){
                    警报(beforeShowForm编辑);
                }
            },
            {//添加选项
                beforeShowForm:功能(FRM){
                    警报(beforeShowForm添加);
                }
            },
            {} // Del选项
            {} //搜索选项
        );
}&LT; D​​IV&GT;
    &LT;%= Html.Trirand()的jqGrid(Model.MyGridmyGrid)%&GT;
&LT; / DIV&GT;


解决方案

我结束了购买支付jqGrid的版本 - 由能够使用干净的.NET对象模型相比的JavaScript将支付本身的时候,我救在任何时间。

在回答这个问题从Trirand支持直接的就是

您可以使用客户端事件AfterEditDialogShown和AfterAddDialogShown禁用/启用这两个对话框编辑字段。编辑/现场加入将具有相同的ID是数据字段(区分大小写)。例如:

型号:

  JQGrid1.ClientSideEvents.AfterEditDialogShown =disableFields;
JQGrid1.ClientSideEvents.AfterEditDialogShown =enableFields;

查看:

 &LT;脚本类型=文/ JavaScript的&GT;    功能disableFields(){
        //jQuery(\"#fieldname\").attr(\"disabled,已禁用);
        $(#源)ATTR(禁用,真)。
        $(#ProgramName中),ATTR(禁用,真)。
        $(#司),ATTR(禁用,真)。
        $(#中)ATTR(禁用,真)。
        $(#内容),ATTR(禁用,真)。
    }    功能enableFields(){
        $(#源)ATTR(禁用,假)。
        $(#ProgramName中),ATTR(禁用,假)。
        $(#司),ATTR(禁用,假)。
        $(#中)ATTR(禁用,假)。
        $(#内容),ATTR(禁用,假)。
    }&LT; / SCRIPT&GT;

I'm attempting to use jqGrid in my ASP.Net MVC application and have a requirement that some columns arre editable in the Add dialog but not the Edit dialog. Apparently the way to do this is to use the beforeShowForm javascript event and set the properties on the particular input field.

So far I can't manage to get the beforeShowForm event to fire. Below is an example I found on another SO question but so far I haven't managed to get it working. Is there some trick I'm missing? I'm using the latest 3.8 version of jqGrid.

Controller:

 [Authorize]
 public ActionResult Index()
 {
      var gridModel = new MyGridModel();
      SetUpGrid(gridModel.MyGrid);
      return View(gridModel);
 }

 private void SetUpGrid(JQGrid grid)
 {
        grid.DataUrl = Url.Action("GridDataRequested");
        grid.EditUrl = Url.Action("EditRows");
        grid.ToolBarSettings.ShowSearchToolBar = false;

        grid.ToolBarSettings.ShowEditButton = true;
        grid.ToolBarSettings.ShowAddButton = true;
        grid.ToolBarSettings.ShowDeleteButton = true;
        grid.ToolBarSettings.ShowRefreshButton = true;
        grid.EditDialogSettings.CloseAfterEditing = true;
        grid.AddDialogSettings.CloseAfterAdding = true;

        grid.EditDialogSettings.Modal = false;
        grid.EditDialogSettings.Width = 500;
        grid.EditDialogSettings.Height = 300;

        grid.ClientSideEvents.GridInitialized = "initGrid";
 }

Model:

public class MyGridModel
{
    public JQGrid MyGrid { get; set; }

    public MyGridModel()
    {
      MyGrid = new JQGrid
      {
        Columns = new List<JQGridColumn>()
        {
            new JQGridColumn { DataField = "id", 
                               PrimaryKey = true,
                               Visible = false,
                               Editable = false },
            new JQGridColumn { DataField = "username", 
                               Editable = true,
                               EditFieldAttributes = new List<JQGridEditFieldAttribute>()
                               {
                                     new JQGridEditFieldAttribute(){ Name = "readonly", Value = "true"},
                                     new JQGridEditFieldAttribute(){ Name = "disabled", Value = "true"}
                                },
                                Width = 100},
            new JQGridColumn { DataField = "domain", 
                               Editable = true,
                               EditFieldAttributes = new List<JQGridEditFieldAttribute>()
                               {
                                    new JQGridEditFieldAttribute(){ Name = "readonly", Value = "true"},
                                    new JQGridEditFieldAttribute(){ Name = "disabled", Value = "true"}
                                },
                                Width = 100}
              }
          }
     }
}

View:

function initGrid() {

  jQuery("#myGrid").jqGrid('navGrid','#myGrid-pager',
            { }, //options
            { // edit options
                beforeShowForm: function(frm) {
                    alert("beforeShowForm edit");
                }
            },
            { // add options
                beforeShowForm: function(frm) {
                    alert("beforeShowForm add");
                }
            },
            { }, // del options
            { } // search options
        );
}

<div>           
    <%= Html.Trirand().JQGrid(Model.MyGrid, "myGrid") %>
</div>

解决方案

I ended up buying the paid for version of jqGrid - the time I save by being able to use a clean .Net object model compared to javascript will pay for itself in no time.

The answer to this question direct from Trirand support is.

You can use the client-side events AfterEditDialogShown and AfterAddDialogShown to disable/enable edit fields for both dialogs. The field for editing/adding will have the same ID is the DataField (case-sensitive). Example:

Model:

JQGrid1.ClientSideEvents.AfterEditDialogShown="disableFields";
JQGrid1.ClientSideEvents.AfterEditDialogShown="enableFields";

View:

<script type="text/javascript">

    function disableFields() {
        //jQuery("#fieldname").attr("disabled", "disabled");
        $("#Source").attr("disabled", "true");
        $("#ProgramName").attr("disabled", "true");
        $("#Division").attr("disabled", "true");
        $("#Medium").attr("disabled", "true");
        $("#content").attr("disabled", "true");
    }

    function enableFields() {
        $("#Source").attr("disabled", "false");
        $("#ProgramName").attr("disabled", "false");
        $("#Division").attr("disabled", "false");
        $("#Medium").attr("disabled", "false");
        $("#content").attr("disabled", "false");
    }

</script>

这篇关于jqGrid的需要编辑的字段上添加对话框,但不能编辑对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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