【问题标题】:Add Custom Button in Edit Form在编辑表单中添加自定义按钮
【发布时间】:2014-04-15 06:06:35
【问题描述】:

我在我的 jqGrid 编辑表单中添加了一个自定义按钮,使用 beforeShowForm 事件创建。 Onclick 自定义按钮我想执行 ADD 操作。 下面是我的代码..

 beforeShowForm: function(form) { 
          //Create Custom ADD Button
          $('<a href="#">Add<span class="ui-icon ui-icon-disk"></span></a>')
            .click(function() {
                var $self = $(this);
               $self.jqGrid("editGridRow", $self.jqGrid("getGridParam", "selrow"),
                {
                  editData: {//Function to Add parameters to the status 
                    oper: 'add', //trying to pass parameter to server
                  },
                });
            }).addClass("fm-button ui-state-default ui-corner-all fm-button-icon-left")
              .prependTo("#Act_Buttons>td.EditButton");

守则
editData: {//Function to Add parameters to the status oper: 'add', //trying to pass parameter to server },

显示 TypeError: a(...)[0].p is undefined 错误。知道如何实现这一目标吗?

【问题讨论】:

    标签: jquery jqgrid


    【解决方案1】:

    您的代码中的主要错误是您使用this 的地方。 beforeShowForm 内部是 this 初始化为网格的 DOM,但在 click 事件处理程序内部 $('&lt;a href="#"&gt;Add&lt;span class="ui-icon ui-icon-disk"&gt;&lt;/span&gt;&lt;/a&gt;') 它被初始化为 &lt;a&gt; 元素。所以你得到错误“TypeError: a(...)[0].p is undefined”。要修复代码,您只需在外部回调函数 beforeShowForm 中移动 $this 变量的初始化

    beforeShowForm: function(form) { 
        var $self = $(this); // !!! place it here !!!
    
        //Create Custom ADD Button
        $('<a href="#">Add<span class="ui-icon ui-icon-disk"></span></a>')
            .click(function() {
                $self.jqGrid("editGridRow", $self.jqGrid("getGridParam", "selrow"), {
                    editData: {//Function to Add parameters to the status 
                        oper: 'add', //trying to pass parameter to server
                    },
                });
            }).addClass("fm-button ui-state-default ui-corner-all fm-button-icon-left")
              .prependTo("#Act_Buttons>td.EditButton");
    }
    

    【讨论】:

    • 谢谢。你说的对。但它没有被发布到服务器。我想我不需要在这里传递 url。有什么想法吗??
    • @Wahab:不客气!发布到服务器取决于您在 jqGrid 中使用的其他选项。您是否设置了例如editurl?或者,您可以直接使用url$self.jqGrid("editGridRow", $self.jqGrid("getGridParam", "selrow"), { url: "yourServerUrl", editData: {... }});
    • 我使用editurl。我想在编辑表单中实现“添加”操作。为此我需要新的网址还是可以使用带有 oper:add 的编辑网址??
    • @Wahab:我不完全理解你在做什么以及为什么需要附加添加按钮。所以我只是试图修复错误"TypeError: a(...)[0].p is undefined"。标准方法是使用"new" 参数作为rowid(参见the documentation)。我不明白当一个人已经打开添加/编辑时,哪种感觉可以调用editGridRow。你需要做什么?可能你只需要在onclickSubmit 回调中有一些逻辑?
    • 我拥有的是一个基本的添加/编辑/删除功能。首先我有一个正常的添加表格。在编辑表单中,我希望执行添加和编辑操作,以便用户在从网格中选择要编辑的行时,他们可以 addedit。当用户想要为相同的名称、宽度和内容添加不同的颜色时,这很有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 2021-10-28
    相关资源
    最近更新 更多