Displaying Empty Cell When Min Date
Environment
Product Version | 2022.3.1109 |
Product | Telerik UI for ASP.NET Core Grid |
Description
How can I display an empty string when the field value is the minimum Date value?
Solution
- Use a ClientTemplate for the pointed column.
- Call a JavaScript function in the ClientTemplate and pass the current dataItem as a parameter.
- In the function handler, initialize a custom variable with value the min one for the Date type.
- Add one day to the custom variable from point 3 to handle all the timezone transformations.
- Conditionally check if the date field of the dataItem has value less than the value of the custom variable.
- If the condition is results in true - return an empty string.
- Else - return the date value in the proper format.
- Here is an example:
columns.Bound(p => p.OrderDate).ClientTemplate("#=orderDetails(data)#");
<script>
function orderDetails(order) {
var minDate = new Date('0001-01-01T00:00:00Z');
minDate.setDate(minDate.getDate() + 1);
if (order.OrderDate < minDate) {
return "";
}
else {
return kendo.toString(order.OrderDate, "g");
}
}
</script>