I am using jqGrid and adding buttons dynamically to the grid. After adding those buttons, in the gridComplete attribute, I call my function:
function(){
var ids = jQuery("#dataTable").jqGrid('getDataIDs');
for(var i=0;i < ids.length;i++){
var cl = ids[i];
$('.ui-loader.ui-corner-all.ui-body-a.ui-loader-default').remove();
$('#create_' + cl).on('click', function() {
var $popUp = $("<div/>").popup({
dismissible : true,
theme : "b",
overlyaTheme : "e",
transition : "pop"
}).on("popupafterclose", function() {
$(this).remove();
}).css({
'width' : '100%',
'height' : '100%',
'padding' : '5px'
})
$("<a>", {
text : "Edit",
}).buttonMarkup({
inline : false,
mini : true,
}).on("click", function() {
$popUp.popup("close");
$('#dataTable').jqGrid('editGridRow', cl);
}).appendTo($popUp);
$("<a>", {
text : "Delete"
}).buttonMarkup({
inline : false,
mini : true,
}).on("click", function() {
$popUp.popup("close");
}).appendTo($popUp);
$popUp.popup('open').trigger("create");
});
}
which works fine except for one problem. It seems that the dynamic buttons all receive the same function (clicking on the button in the first row calls what should have been called for the last row, clicking the second button calls the last row's function, etc...) So it seems that I cannot dynamically assign onclick to a large set of buttons. When I think about it I come to think that it should be possible to assign the click methods for each button this way, but I am not really sure, as I am new to jquery/jqgrid. Is there any way to fix this?
Here is my code to add the buttons:
function displayButton(cellvalue, options, rowObject){var act = "<div id='page_" + options.rowId + "'> <a href='#' data-role='button' id='create_"+ options.rowId +"'>Create a popup</a></div>"
return act; return act;}
which is called by the model of the jqgrid's row.
formatter: displayButton