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

5 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
    Admin
    Dimiter Madjarov avatar
    2213 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.
    E.g.

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

    Regards,
    Dimiter Madjarov
    Telerik
    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.
  4. PRASHANT
    PRASHANT avatar
    1 posts
    Member since:
    Dec 2016

    Posted 21 Sep in reply to Matias Link to this post

    Is there any way to open bootstrap model popup with link
  5. Stefan
    Admin
    Stefan avatar
    1288 posts

    Posted 25 Sep Link to this post

    Hello, Prashant,

    I can suggest checking the following forum post and a similar subject, as it contains information how it can be achieved:

    http://www.telerik.com/forums/opening-bootstrap-modal-from-url-in-grid-column

    I hope this is helpful.

    Regards,
    Stefan
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top