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 to column content in grid

Hello

i have grid as follow.

View:

@(Html.EJ().Grid<object>("RecentlyViewedAccounts")

            .Datasource((System.Data.DataTable)ViewBag.vieweddatasource)

            .AllowSorting()

            .AllowResizing()

            .EnableRowHover(true)

          .Columns(col =>

          {

              col.Field("currentUserId").HeaderText("User").Add();

              col.Field("AccountGroupName").HeaderText("Account Name").Add();

              col.Field("VisitedDate").HeaderText("Visited Date").TextAlign(TextAlign.Center).Format("{0:MM/dd/yyyy}").Width(100).Add();

             

          }))

 I want hyperlink to each content in  "AccountGroupName" field, where the account group name is updated for every visit.
so what will be the script for template field?

if need controller
controller: 

 public void InsertRecentlyViewedAccounts(string currentUserId, string AccountGroupName, DateTime VisitedDate) 
        {
            //For recentlyviewedAccounts Grid on home page
            DataTable dtRecViewedAcc = new DataTable();
            DBDatabase dbManager = DBDatabase.Create("ARAContext");
            List<DBParam> values = new List<DBParam>();

            values.Add(DBParam.ParamWithValue (DbType.StringFixedLength,currentUserId));
            values.Add(DBParam.ParamWithValue(DbType.StringFixedLength, AccountGroupName));
            values.Add(DBParam.ParamWithValue(DbType.DateTime, VisitedDate));
            DBSelectQuery selectQuery = DBQuery.SelectAll()
                                               .From("RecentlyViewedAccounts").Where(DBField.Field("AccountGroupName"), Compare.Equals, DBParam.ParamWithValue(AccountGroupName)).And(DBField.Field("currentUserId"), Compare.Equals, DBParam.ParamWithValue(currentUserId));
            dbManager.ExecuteRead(selectQuery, reader =>
            {
                dtRecViewedAcc.Load(reader);
            });
            if (dtRecViewedAcc.Rows.Count > 0)
            {
                // update the existing record
                DBUpdateQuery strUpdateQuery = DBQuery.Update("RecentlyViewedAccounts")
                                        .Set("VisitedDate", DBParam.ParamWithValue(VisitedDate.Date))
                                        .Where(DBField.Field("AccountGroupName"), Compare.Equals, DBParam.ParamWithValue(AccountGroupName)).AndWhere(DBField.Field("currentUserId"), Compare.Equals, DBParam.ParamWithValue(currentUserId));
                dbManager.ExecuteNonQuery(strUpdateQuery);
            }
            else
            {
                DBInsertQuery strInsertQuery = DBQuery.InsertInto("RecentlyViewedAccounts")
                    .Fields("currentUserId", "AccountGroupName","VisitedDate")
                    .Values(values.ToArray<DBParam>());
                dbManager.ExecuteNonQuery(strInsertQuery);
            }
        }

3 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team October 26, 2015 10:21 AM UTC

Hi Gajanan,

Thanks for contacting Syncfusion support.

Your requirement has been achieved by using columnTemplate property of the ejGrid. A Column template is used to render a specific template to a particular column using Template and TemplateID property. In this template, we can render the images or checkboxes or any html elements to the column. So, using the column template we can render the hyperlink content for the particular column.

Please find the code example and sample:



@(Html.EJ().Grid<object>("FlatGrid")

        .Datasource((IEnumerable<object>)ViewBag.datasource)

        .AllowSorting()

        .AllowFiltering()

        .ClientSideEvents(eve => eve.RecordClick("recordclick"))

        .Columns(col =>

        {

            col.Field("EmployeeID").HeaderText("Employee ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

            col.HeaderText("Employee Image").Template(true).TemplateID("#columnTemplate").TextAlign(TextAlign.Center).Field("LastName").Width(110).Add();

            col.Field("FirstName").HeaderText("First Name").Width(100).Add();

            col.Field("Title").Width(120).Add();

            col.Field("City").Width(100).Add();

            col.Field("Country").Width(100).Add();

        })

        )

<script type="text/x-jsrender" id="columnTemplate">

    <a rel='nofollow' href="http://www.syncfusion.com/">{{:LastName}}</a>

</script>




Sample: http://www.syncfusion.com/downloads/support/forum/120860/ze/Sample145862_(2)704426861

Refer to the Help document for the Column Template API.

ColumnTemplate: http://help.syncfusion.com/aspnetmvc/grid/columns#template

We also created a KB documentation to place hyperlink in the grid columns. Please find the documentation from the following link

http://www.syncfusion.com/kb/3767/how-to-place-hyperlink-in-grid-column

Query : “where the account group name is updated for every visit”

While clicking the hyperlink content, you want a post to the controller with the selected records. If not, could you please elaborate the requirement, it will be helpful to provide a better solution.

Regards,
Prasanna Kumar N.S.V



J J January 10, 2020 07:06 AM UTC

Another very bad, useless answer. I swear do you guys even know what you are doing. I am pulling out my hair trying to do the simplest things with this grid.
WTF is {{:Lastname}} -- I would guess it puts the value of  field 'Lastname' where you put the "{{:Lastname}}. It does not!!!

I tried this:
 col.Field("Id").HeaderText("").Template("<a rel='nofollow' href='/Management/Select'>{{:Id}}</a>").Width(100).Add();
or
 col.Field("Id").HeaderText("").Template("<a rel='nofollow' href='/Management/Select?arg={{:Id}}'>Select</a>").Width(100).Add();

Guess what displays:
{{:Id}}

This is really basic functionality, I have been digging for hours.

And stop posting zipped samples and put them on github. It takes me 5-10 min to download a zip, unzip it, look through it to find out is is useless.
At least I can quickly search and view it in github.

I am very disappointed in this grid and am considering going back to Telerik, or even basic built-in MVC


PK Padmavathy Kamalanathan Syncfusion Team January 13, 2020 10:41 AM UTC

Hi J, 

QUERY: Issue with column template 
 
The “LastName” is a field name. And the format specified our last post works fine. We have also created a sample for your reference and shared you here the github link. 

Please check the sample, 

You can also check how we have defined the column template in the below view page, 

In the above sample, we have used “CustomerID” field name in the template. We suggest you to use a “Valid Field Name” so that the column template will be rendered properly. 

Still facing the issue, please share us below details, 
  1. Complete grid rendering code zipped
  2. Version details
  3. Screenshot of error if any
 
If you have further queries, please get back to us. 

Regards, 
Padmavathy Kamalanathan 


Loader.
Live Chat Icon For mobile
Up arrow icon