Can't create column with link to personal page

1 Answer 64 Views
Grid
kva
Top achievements
Rank 2
Iron
Iron
Iron
kva asked on 08 Aug 2023, 07:45 AM

That's what I tried:

columns.Command(c => c.Custom("Page").Template("<a href=/Directory/User/${Id}>Page</a>"));

I got:

ReferenceError: Id is not defined in /Directory/Users

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 09 Aug 2023, 02:47 PM

Hello,

By desing, the underlying data item cannot be accessed in the column commands. However, I would suggest the following approach:

  • Attach the "onclick" event to the anchor tag and disable the "href" attribute.
  • Get a reference to the Grid and call the dataItem() method to access the respective data item.
  • Use the "location.href" property to redirect the user to the appropriate URL.
columns.Command(c => c.Custom("Page").Template("<a href='javascript:;' onclick='getUserPage(event);'>Page</a>"));

<script type="text/javascript">
    function getUserPage(e) {
        var grid = $("#grid").getKendoGrid(); //get the Grid instance
        var dataItem = grid.dataItem($(e.currentTarget).closest("tr")); //get the data item
        location.href = "/Directory/User/" + dataItem.Id;
    }
</script>

I hope that helps.

 

Regards, Mihaela Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Tags
Grid
Asked by
kva
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Mihaela
Telerik team
Share this question
or