I am trying to make the text in a td element be a clickable link which calls a callback function which will then open a read-only details window. I want the text to look like a link so the user knows to click it. The way it was before is you could click the whole table row, but there is no indication that it is even clickable. Also, I want only the text of a specific column to be clickable.
This is the anchor I’m adding to the target cell, which is taking place inside the init function for the object:
$(td).html('<a href="#" onclick="object.myFunction.call(this)">' + cellData + '</a>');
Then this is the callback function taking place outside the init:
grid.readOnlyModalCallback = function () {
let guid = $(this).data("guid");
if (guid) {
grid.showDetailModal(guid);
}
return false;
};
This makes the text a link like I want, but it does nothing when clicked except redirect the page to "#".
I know the function works because it will call if I make the whole row clickable, like I mentioned.
Can anybody determine what I’m doing wrong?
2
Answers
It seems like you are trying to bind the click event on the link to
object.myFunction
but what you actually want is to bind it togrid.readOnlyModalCallback
.Use
jQuery.data()
to store the guid with the link:Then bind the click event to the links using
jQuery.on()
in your init function:Make sure you’re preventing the default event in your callback:
Simply add a
click
event handler to thetd
and style thetd
to make it clear that it can be clicked.See example below: