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.
Unfortunately, activation email could not send to your email. Please try again.

Hyperlink to column content in grid

Thread ID:

Created:

Updated:

Platform:

Replies:

120860 Oct 23,2015 04:42 AM Oct 26,2015 06:21 AM ASP.NET MVC 1
loading
Tags: Grid
Gajanan Deshpande
Asked On October 23, 2015 04:42 AM

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);
            }
        }

Prasanna Kumar Viswanathan [Syncfusion]
Replied On October 26, 2015 06:21 AM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;