Answer the question
In order to leave comments, you need to log in
What could be the problem when handling the click event of a link in a jqGrid cell?
There is a table based on jqGrid, for one of the cells a custom fromatter is used:
function employeeLinkFormatter(cellvalue, optios, rowObject) {
if (cellvalue) {
var name = cellvalue;
var id = rowObject["ResponsiblePersonId"];
if (id) {
var link = '@Html.ActionLink("Name", "EmployeeInfo", "Customers", new { employeeId = "EmployeeId" }, new { @class = "modalpartial" })';
var result = link.replace("Name", name).replace("EmployeeId", id);
return result;
}
return name;
}
return "";
}
$(".modalpartial").click(function (ev) {
try {
ev.preventDefault();
var url = $(this).attr("href");
var placeholder = document.getElementById("_modal_placeholder");
$("<div id=\"modalpartialwindow\" class=\"modal fade \" tabindex=\"-1\"/>").appendTo(placeholder);
$("<div id=\"modaldialog\" class=\"modal-dialog modal-lg\" />").appendTo("#modalpartialwindow");
$("<div id=\"modalpartialcontainer\" class=\"modal-content\"/>").appendTo("#modaldialog");
$.ajaxSetup({ cache: false });
$.get(url, function (data) {
$("#modalpartialcontainer").html(data);
$("#modalpartialwindow").modal("show");
});
} catch (e) {
alert("Ошибка " + e.message + " " + e.description);
}
return false;
});
Answer the question
In order to leave comments, you need to log in
The problem is most likely that at the time of binding the click, there are no elements with the modalpartial class on the page yet.
Try
writing instead of a line
$(document).on("click", ".modalpartial", function (ev) {
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question