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

Date ClientTemplate and EditorTemplateName for Nullable or 0 Dates

1 Answer 338 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cynthia
Top achievements
Rank 1
Cynthia asked on 16 Apr 2013, 06:55 PM
In our database, we use 0 (which resolves as 1/1/1900) for dates.

We don't have nullable dates.

What is the best practice such that dates that come into the model is 0 (or1/1/1900), format so in display mode they appear as "--" or "n/a" or "", while in edit mode, the control shows an empty box, instead of 1/1/1900?


1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 18 Apr 2013, 12:28 PM
Hi Cynthia,

 
This is possible using ClientTemplate(for the display mode) and Edit event(for edit mode) to check if the current date is equal to your custom date to apply custom template / empty the editor. Please check the example below:

Grid configuration:

    columns.Bound(p => p.OrderDate).Format("{0:d}").ClientTemplate("#=formatDate(OrderDate)#");
    columns.Command(c => {
        c.Edit();
        c.Destroy();
    });
})   
.Events(e => e.Edit("onEdit"))

JavaScript:
$(function () {
    formated1900 = kendo.format("{0:d}", new Date(1900, 0, 1));
})
 
function onEdit(e) {
         
    var formatedOrderDate = kendo.format("{0:d}", e.model.OrderDate);
    //consider handle the user and server time offset:
    if (formated1900 == formatedOrderDate) {
        this.tbody.find("[name=OrderDate]").data("kendoDateTimePicker").value("");
    }
}
 
function formatDate(OrderDate) {
 
    var formatedOrderDate = kendo.format("{0:d}", OrderDate);
    //consider handle the user and server time offset:
    if (formated1900 == formatedOrderDate) {
        return "--";
    }
    else {
        return formatedOrderDate;
    }
}

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Cynthia
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or