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
close icon

Grid Hyperlink Column Using Date Value

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


5 Replies

GV Gowthami V Syncfusion Team 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.


JS Jeffrey Stone 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


GV Gowthami V Syncfusion Team 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.


JS Jeffrey Stone February 24, 2016 05:33 PM UTC

Worked perfectly! Thanks!


GV Gowthami V Syncfusion Team 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.

Loader.
Live Chat Icon For mobile
Up arrow icon