jqgrid在dataInit中区分添加和编辑表单 [英] jqgrid differentiate in dataInit add and edit forms

查看:1051
本文介绍了jqgrid在dataInit中区分添加和编辑表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何区分dataInit事件我是在添加新数据还是编辑它?

How I can differentiate in the dataInit event wether am I adding new data or editing it?

提前致谢。

推荐答案

这是一个很好的问题!来自我的+1。

It's a good question! +1 from me for it.

没有直接的方法来检测 dataInit 是否从添加或编辑表单。以同样的方式使用多种编辑模式(如表单编辑内联编辑)和多种搜索模式(提前搜索对话框和搜索工具栏)没有直接的方法来检测控件的使用位置。

There are no direct way to detect inside of dataInit whether it is called from Add or Edit form. In the same way if you use multiple editing mode (like form editing and inline editing) and multiple searching modes (advance searching dialog and the searching toolbar) there are no direct way to detect in which place the control are used.

作为解决方法,您可以使用以下内容。您可以定义一个变量,您可以在事件内的不同值中设置该变量,该变量将在 dataInit 之前添加和编辑形式中调用将被召唤。告诉你信任你没有那么大的选择。这只是 beforeInitData 事件。所以你可以这样做

As the workaround you can use the following. You can define a variable which you can set in the different value inside of an event which will be called in both Add and Edit form before the dataInit will be called. To tell the trust you have not so large choice. It's the beforeInitData event only. So you can do like following

var myGrid = $("#list"),
    inEdit;

$("#list").jqGrid({
    // all parameters of the jqGrid definition
});
myGrid.jqGrid('navGrid', '#pager',
  { del: false, search: false },
  { // Edit
      recreateForm: true,
      beforeInitData: function () {
          inEdit = true;
      }
  },
  { // Add
      recreateForm: true,
      beforeInitData: function () {
          inEdit = false;
      }
  });

我使用了 recreateForm:true 属性另外要确保在添加或编辑网格的每个开口处创建新表单和 dataInit 被调用。

I used recreateForm:true property additionally to be sure that on every opening of the Add or Edit grid the form created new and the dataInit be called.

演示添加表单看起来像

这里的 dataInit 表示注释在相应的控件中只写添加文本。 Inv.No是保存id的字段。添加/编辑表单的相应< input> 控件已禁用。因此用户无法进行任何更改。如果是添加对话框,方法 $。jgrid.randId()将用于生成新的唯一ID值。

Here the dataInit for the "Notes" write just the text "in Add" in the corresponding control. The "Inv. No" is the field which hold the id. The corresponding <input> control of the Add/Edit form is disabled. So the user can't make any changes. In case of "Add" dialog the method $.jgrid.randId() will be used to generate new unique id value.

相应的编辑表格如下图所示:

The corresponding Edit form are like on the picture below:

这篇关于jqgrid在dataInit中区分添加和编辑表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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