This is a migrated thread and some comments may be shown as answers.

[Solved] Comparing dates in ClientTemplate

2 Answers 197 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Travis
Top achievements
Rank 1
Travis asked on 19 Apr 2012, 05:51 PM
How do I compare dates in a bound column's ClientTemplate?

I tried the following, but neither seem to work:

.ClientTemplate("<# if (RequestedDueDate>Date()){#> yes <#}#>")
.ClientTemplate("<# if (RequestedDueDate>'" + DateTime.Today.ToShortDateString() + "'){#> yes <#}#>")

My only workaround was to pass the RequestedDueDate to a javascript function which then compared the dates.

2 Answers, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 23 Apr 2012, 11:21 AM
You should change your Model instead.

I presume "Date()" is a server function with return a date right?

public class MyModel
{
public DateTime RequestedDueDate {get; set;}

public bool IsValidDate
{
get
{
return RequestedDueDate>Date();
}
}
// or directly the string but it's not the best way

public string DateState
{
get
{
return RequestedDueDate>Date() ? "yes" : "no";
}
} 


}
0
Shawn
Top achievements
Rank 2
answered on 30 Jun 2012, 12:37 PM
why would returning the string as in your last example not be the best way?
Tags
Grid
Asked by
Travis
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Shawn
Top achievements
Rank 2
Share this question
or