I am using MVC 4 + EF 4.1 with jqgrid. I am new with HTML & Javascript and I am trying without success opening a custom edit jquery dialog inside jqgrid. If you have better methods to implement my desired behaviour, they would be welcome.
I have the following jquery dialog script, attached to the class='openDialog
', which already works fine for other purposes:
$.ajaxSetup({ cache: false });
$(document).ready(function () {
$(".openDialog").live("click", function (e) {
e.preventDefault();
$("<div></div>")
.addClass("dialog")
.attr("id", $(this).attr("data-dialog-id"))
.appendTo("body")
.dialog({
height: $(this).attr("data-dialog-alt"),
width: $(this).attr("data-dialog-larg"),
autoResize: $(this).attr("data-dialog-autosize"),
position: 'top',
title: $(this).attr("data-dialog-title"),
close: function () { $(this).remove() },
modal: true,
buttons: { "Ok": function () { $(this).dialog("close"); } }
})
.load(this.href);
});
$(".close").live("click", function (e) {
e.preventDefault();
$(this).closest(".dialog").dialog("close");
});
});
This is what I'm trying to do. This is just a test with double click event, if it works I will put the code inside a specific button.
jqgrid
..........
{ name: 'act', index: 'act', width: 75, sortable: false, search: false }
],
ondblClickRow: function (id) {
if (id != null) {
// here I would like to launch the open dialog with a similar code:
// "<a class='openDialog' data-dialog-id='myEditDlg' data-dialog-autosize='false' data-dialog-alt='580' data-dialog-larg='740' data-dialog-title='test dialog' href='/mycontroller/EditDlg/myid'>test</a>"
}
},
pager: '#jqpager',
....
MORE DETAILS
Basically, now I am using a custom formatter, where I put a button styled anchor for each button/action I need; for example:
.....
gridComplete: function () {
applyZebra("mygrid");
var ids = grid.jqGrid('getDataIDs');
var rows = grid.jqGrid('getRowData');
for (var i = 0; i < ids.length; i++) {
var row = rows[i];
var t = row['myrow'];
var cl = ids[i];
tst = '<a class="mybuttonclass openDialog" data-dialog-id="tckDetDlg" data-dialog-autosize="false" data-dialog-alt="580" data-dialog-larg="740" data-dialog-title="test dialog" href="/mycontrolller/testDlg/' + t + '"></a>';
$("#jqTicketgrid").jqGrid('setRowData', ids[i], { act: tst });
}
},
.....
Where mybuttonclass styles the anchors like a button...
Thank you very much for your help! Best Regards