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

4 posts, 1 answers
  1. Matias
    Matias  avatar
    26 posts
    Member since:
    Mar 2016

    Posted 07 Apr 2016 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
    2211 posts

    Posted 08 Apr 2016 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. Matias
    Matias  avatar
    26 posts
    Member since:
    Mar 2016

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

    It works fine. Thanks a lot.
    PRASHANT avatar
    1 posts
    Member since:
    Dec 2016

    Posted 2 days and 15 hours ago in reply to Matias Link to this post

    Is there any way to open bootstrap model popup with link
Back to Top