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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid Hyperlink Column Using Date Value

Thread ID:

Created:

Updated:

Platform:

Replies:

123154 Feb 22,2016 02:39 AM UTC Feb 25,2016 03:52 AM UTC ASP.NET MVC 5
loading
Tags: Grid
Jeffrey Stone
Asked On February 22, 2016 02:39 AM UTC

I am trying to have a column with a hyperlink that has 2 arguments. It works great with 1 argument but I am having trouble passing a date that .NET MVC will understand.

I first tried this:
c.Field(r => r.Symbol).Format("<a target='_blank' rel='nofollow' href='" + @Url.Action("Chart", "HistoricalData") + "?symbol={Symbol}&barSize=s60&fromDate={DateAdded}'>{Symbol}</a>").Add();

Here is how the respective date was passed (which .NET translated to a null):
fromDate=Fri Feb 19 2016 12:23:49 GMT-0500 (Eastern Standard Time)

I then tried to a date format specification
c.Field(r => r.Symbol).Format("<a target='_blank' rel='nofollow' href='" + @Url.Action("Chart", "HistoricalData") + "?symbol={Symbol}&barSize=s60&fromDate={DateAdded:MM-dd-yyyy HH:mm:ss}'>{Symbol}</a>").Add();

Here is how the respective date was passed:
fromDate={DateAdded:MM-dd-yyyy HH:mm:ss}

How can I accomplish this?

Regards, Jeff


Gowthami V [Syncfusion]
Replied On February 22, 2016 12:24 PM UTC

Hi Jeffrey,

We can achieve your requirement "format the date in template" by format the date in ISO 8601 format using toJSON method as follows,


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

.Columns(col =>
        {
. . . .

col.Field("OrderDate").HeaderText("Order Date").TextAlign(TextAlign.Right).Width(80).Template("<a target='_blank' rel='nofollow' href='" + @Url.Action("Grid", "DataSource") + "?symbol={{:CustomerID}}&barSize=s60& fromDate="+"{{:OrderDate.toJSON()}}"+"'>{{:CustomerID}}</a>").Add();
       })

)




Regards,

Gowthami V.

Jeffrey Stone
Replied On February 22, 2016 01:49 PM UTC

Gowthami,

Thanks for the quick response.

I tried your suggestion and I received an error. Here is the line that I used:

c.Field(r => r.Symbol).Format("<a target='_blank' rel='nofollow' href='" + @Url.Action("Chart", "HistoricalData") + "?symbol={Symbol}&barSize=s60&fromDate=" + "{{:DateSubmitted.toJSON()}}" + "'>{Symbol}</a>").Add();

Here is the error.

JsRender Error: Syntax error
Compiled template code:

// RecentlyFilledOrdersGrid_JSONTemplate
var j=j||jQuery.views,v,ret="";
try{

ret+="<tr role=\"row\" class=\"";
ret+=(v=view.hlp("_RecentlyFilledOrdersGridAlternateRow")())!=u?v:"";
ret+="\"><td role=\"gridcell\" style=\"text-align: left;\" class=\"e-rowcell\">";
ret+=(v=data["ShortAccountName"])!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: left;\" class=\"e-rowcell\">";
ret+=(v=data["StrategyName"])!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: left;\" class=\"e-rowcell\">";
ret+=(v=view.hlp("_gridFormatting")("<a target=\"_blank\" rel='nofollow' href=\"/Euclid/HistoricalData/Chart?symbol={Symbol}&amp;barSize=s60&amp;fromDate={{:DateSubmitted.toJSON())!=u?v:"";
ret+="\">{Symbol}</a>\',#data[\'Symbol\'],\'en-US\')}}</td><td role=\"gridcell\" style=\"text-align: left;\" class=\"e-rowcell\">";
ret+=(v=data["Action"])!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell\">";
ret+=(v=view.hlp("_gridFormatting")("{0:N0}",data["Quantity"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell\">";
ret+=(v=view.hlp("_gridFormatting")("{0:C2}",data["ThumperTargetPrice"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell e-hide\">";
ret+=(v=view.hlp("_gridFormatting")("{0:C2}",data["LimitPrice"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell\">";
ret+=(v=view.hlp("_gridFormatting")("{0:C2}",data["AverageFillPrice"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell\">";
ret+=(v=view.hlp("_gridFormatting")("{0:C0}",data["ThumperSlippageAmount"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell\">";
ret+=(v=view.hlp("_gridFormatting")("{0:P2}",data["ThumperSlippagePercent"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell e-hide\">";
ret+=(v=view.hlp("_gridFormatting")("{0:N0}",data["QuantityFilled"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell\">";
ret+=(v=view.hlp("_gridFormatting")("{0:C2}",data["CommissionAmount"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell\">";
ret+=(v=view.hlp("_gridFormatting")("{0:C4}",data["CommissionPerShare"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: left;\" class=\"e-rowcell\">";
ret+=(v=data["OrderStatus"])!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell\">";
ret+=(v=data["ThumperOrderId"])!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: left;\" class=\"e-rowcell\">";
ret+=(v=data["ThumperSettingsName"])!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: right;\" class=\"e-rowcell\">";
ret+=(v=view.hlp("_gridFormatting")("{0:N0}",data["MillisecondsToFill"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: left;\" class=\"e-rowcell\">";
ret+=(v=view.hlp("_gridFormatting")("{0:HH:mm:ss}",data["DateSubmitted"],"en-US"))!=u?v:"";
ret+="</td><td role=\"gridcell\" style=\"text-align: left;\" class=\"e-rowcell e-hide\">";
ret+=(v=view.hlp("_gridFormatting")("{0:HH:mm:ss}",data["DateFilled"],"en-US"))!=u?v:"";
ret+="</td></tr>";
return ret;

}catch(e){return j._err(e);}
https://xxxxx/Scripts/jsrender.min.js
Line 1

Gowthami V [Syncfusion]
Replied On February 23, 2016 10:03 AM UTC

Hi Jeff,

We have analyzed your code example and we have found that you are passing hyperlink in Format property.

In Format property the complex values will not get evaluated.

Due to this reason the toJSON method is not evaluated and raised the script error.

We can resolve the above mentioned scenario using “Template” property of the columns as follows,

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

.Columns(c =>
        {
c.Field(r => r.Symbol).Template("<a target='_blank' rel='nofollow' href='" + @Url.Action("Chart", "HistoricalData") + "?symbol={{:Symbol}}&barSize=s60&fromDate=" + "{{:DateSubmitted.toJSON()}}" + "'>{{:Symbol}}</a>").Add();
. . . .

})                


)


Refer to the below link for more clarification about Template property,

http://help.syncfusion.com/js/grid/columns#column-template

Regards,

Gowthami V.

Jeffrey Stone
Replied On February 24, 2016 05:33 PM UTC

Worked perfectly! Thanks!

Gowthami V [Syncfusion]
Replied On February 25, 2016 03:52 AM UTC

Hi Jeff,
 
We are happy to hear that your issue has been resolved.
 
Get back to us if you need further assistance.
 
Regards,
 
Gowthami 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.

Warning Icon 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.Close Icon

;