MVC Grid hierarchy - add link to javascript function on child grid column

3 posts, 1 answers
  1. Matias
    Matias  avatar
    22 posts
    Member since:
    Mar 2016

    Posted 07 Apr Link to this post

    I'm trying to add a onClick JS function to a certain column in the child grid, but so far with no luck.


    This is my column:

    columns.Bound(o => o.oper_numero).Width(110).ClientTemplate("<a onclick=\"showDetails('#=oper_numero#')\" href='\\#'>#=oper_numero#</a>");

    I achieved the desired functionality with both a non hiearchy grid and the parent grid.

    I've read that I have to escape the the # symbol in the child grid, but I've tried every combination and still doesn't work. This for example doesn't work:

    columns.Bound(o => o.oper_numero).Width(110).ClientTemplate("<a onclick=\"showDetails('#=oper_numero#')\" href='\\#'>\\#'=oper_numero\\#'</a>");
    columns.Bound(o => o.oper_numero).Width(110).ClientTemplate("<a onclick=\"showDetails('\\#'=oper_numero\\#'')\" href='\\#'>#=oper_numero#</a>");
    columns.Bound(o => o.oper_numero).Width(110).ClientTemplate("<a onclick=\"showDetails('\\#'=oper_numero\\#'')\" href='\\#'>\\#=oper_numero\\#</a>");

    I'd like to know what I'm doing wrong.

    Thanks a lot

  2. Answer
    Dimiter Madjarov
    Dimiter Madjarov avatar
    2127 posts

    Posted 08 Apr Link to this post

    Hello Matias,

    The reason for the issue is the hash symbol in the href attribute, which is not part of the template syntax. Here is the correct way to define the link on the second Grid level in this case.

    .ClientTemplate("<a href='\\\\\\#' onclick=\"showDetails('\\#=oper_numero\\#')\">\\#=oper_numero\\#</a>")

    Dimiter Madjarov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET AJAX bannerTelerik UI for ASP.NET Core is out
  4. Matias
    Matias  avatar
    22 posts
    Member since:
    Mar 2016

    Posted 13 Apr in reply to Dimiter Madjarov Link to this post

    It works fine. Thanks a lot.
Back to Top