New to Telerik UI for ASP.NET MVC? Download free 30-day trial

Displaying Empty Cell When Min Date

Environment

Product Version 2022.3.1109
Product Telerik UI for ASP.NET MVC Grid

Description

How can I display an empty string when the field value is the minimum Date value?

Solution

  1. Use a ClientTemplate for the pointed column.
  2. Call a JavaScript function in the ClientTemplate and pass the current dataItem as a parameter.
  3. In the function handler, initialize a custom variable with value the min one for the Date type.
  4. Add one day to the custom variable from point 3 to handle all the timezone transformations.
  5. Conditionally check if the date field of the dataItem has value less than the value of the custom variable.
  6. If the condition is results in true - return an empty string.
  7. Else - return the date value in the proper format.
  8. 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>

More ASP.NET MVC Grid Resources

See Also

In this article