We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Hyperlink

How can I create hyperlink in a column with col.Field value as text? 
What I want to get is to click on the name of the employee in the grid to get it's details.

Thanks,
and best wishes for the New Year.

5 Replies

SA Saravanan Arunachalam Syncfusion Team January 2, 2017 06:44 AM UTC

Hi Bernard, 
Thanks for contacting Syncfusion’s support. 
Query 1: How can I create hyperlink in a column with col.Field value as text? 
We have already discussed this query in the following Knowledge Base document. 
Query 2: What I want to get is to click on the name of the employee in the grid to get it's details. 
We have achieved your requirement by using “RecordClick” event of Grid control and refer to the below code example.  
@(Html.EJ().Grid<object>("FlatGrid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
        
        .ClientSideEvents(eve => eve.RecordClick("recordclick")) 
        .Columns(col => 
        { 
            col.Field("EmployeeID").HeaderText("Employee ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); 
            col.Field("EmployeeName").HeaderText("Name").Width(100).Add(); 
            col.Field("City").Width(100).Add(); 
             
        }) 
) 
<script> 
    function recordclick(args) { 
        //Get the details of the row when click the name of the employee 
        if ($(args.cell).index() == 1) { 
            alert("Employee ID:" + args.data.EmployeeID + "\nName:" + args.data.EmployeeName + "\nCity:" + args.data.City); 
        } 
    } 
</script> 
 
Regards, 
Saravanan A. 



BJ Bernard Jurlina January 2, 2017 10:18 PM UTC

Hi Saravanan,

thanks for answering my questions. You gave me the link to Knowledge Base for creating a hyperlink in a column. I saw that before, but, If you look at the picture of grid in that example, column "Manage records" has fixed text "View", which is text for the hyperlink. 
col.HeaderText("Manage Records").Template(" <a rel='nofollow' href='#''>View</a>").Add();
I do not want to have fixed text for that, I want values from column OrderID, for example, as text for the hyperlink. So, how can I replace "View" in template with cell value?

Thank You.
Bernard.




SA Saravanan Arunachalam Syncfusion Team January 3, 2017 09:03 AM UTC

Hi Bernard, 
By default Grid uses JsRender template and we can achieve your requirement with the below code example. 
@(Html.EJ().Grid<object>("FlatGrid") 
          . . . 
        .Columns(col => 
        { 
            . . . 
            col.HeaderText("Manage Records").Template("<a rel='nofollow' href='#''>{{:OrderID}}</a>").Add(); 
             
        }) 
) 
 
Regards, 
Saravanan A. 



BJ Bernard Jurlina January 3, 2017 10:24 PM UTC

Excellent, it works like a charm.

Thank You once again!

Bernard.


PS Pavithra Subramaniyam Syncfusion Team January 4, 2017 06:09 AM UTC

Hi Bernard,
Thanks for your update.          
We are happy that the provided information helped you.
Regards,
Pavithra S.
​​​

Loader.
Up arrow icon