The main error in your code is the place where you use this
. Inside of beforeShowForm
is this
initialized to the DOM of the grid, but inside of click
event handler to $('<a href="#">Add<span class="ui-icon ui-icon-disk"></span></a>')
it's initialized to <a>
element. So you get the error "TypeError: a(...)[0].p is undefined". To fix the code you need just move initializing of $this
variable in the outer callback function beforeShowForm
:
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");
}