A
A
alrdev2016-02-05 08:56:01
JavaScript
alrdev, 2016-02-05 08:56:01

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 "";
    }


As planned, when clicking on the link, a modal window appears (based on PartialView) formed by the following code:
$(".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;
    });


If the link is placed outside the jqGrid, then the window is shown (the $(".modalpartial").click event is called), but if the link is in a cell, the html (PartialView) is simply opened, without triggering the event and processing it.
Tell me, where did I mess up?
I'm just pretty far from Jquery and others like it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Zuev, 2016-02-05
@alrdev

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 question

Ask a Question

731 491 924 answers to any question