Search code examples
javascriptasp.net-mvcsyncfusion

Add hyperlink to some cells in syncfusion treegrid - ASP.NET MVC


I want to add a link to EJ TreeGrid and I want pass the column's on href.

col.Field("NoteID")
                      .HeaderText("View")
                      .Width(80)
                      .TextAlign(TextAlign.Right)
                      .IsTemplateColumn(true)
                      .Template("<a href='" + @Url.Action("GetNoteID", "Notes") + "/" + "/{NoteID}' target='_blank'>View Broker Note</a>")                     
                      .Add();

How can I pass the pass NoteID on {NoteID} in the href link?

I tried:

.ClientSideEvents(eve =>
                  {
                     eve.QueryCellInfo("querycellinfo");
                  })`

`function querycellinfo(args) {
        if (args.column.field === "NoteID" && args.cellValue != null) {
            $(args.cellElement).find(".linkbtn").click(function () {
                $.ajax({
                    type: "GET",
                    url: @Url.Action("GetNoteID", "Notes") + "/" + args.cellValue,
                    data: args.data,
                    dataType: "json"
                });
            })
        }
    }

but with no luck.


Solution

  • To address your requirement, we have provided a sample where we used template in the column to provide a hyperlink and passed the taskname value using double curly braces with Colon {{: }}, you can find the code snippet and sample Link below

    Code Snippet:

    /index.cshtml/

    .Columns(co =>

    {
    
     co.Field("TaskName").HeaderText("Task Name").EditType(TreeGridEditingType.String).Template("<a href='" + @Url.Action("GetNoteID", "Notes") + "/" + "/{{:TaskName}}' target='_blank'>View Broker Note</a>").IsTemplateColumn(true).Add();
    

    }

    Sample Link : https://www.syncfusion.com/downloads/support/directtrac/general/ze/TestSample1393020514

    UG LINK : https://help.syncfusion.com/aspnetmvc/treegrid/columns#column-template

    Regards,

    Udhayakumar