4
votes

I am using kendo grid where I have added a column of DateTime type which shows datetime.

The problem which I am facing is that if their is no date set then by default it is showing null value.

What I want is that if no date is set then it should show blank cell value instead of null.

I am using 2012.2.710.340 version of kendo.

Have declare the field value in class in following way :

public DateTime? Time { get; set; }

Below is the format I have used in kendo grid to show datetime field in grid :

columns.Bound(o => o.Time).Format("{0:MM/dd/yyyy HH:mm:ss}").Title("Time");

I will be thankful if anyone could help me out in solving my problem.

3

3 Answers

7
votes

I have tried using kendo.tostring in following way:

columns.Bound(o => o.Time).ClientTemplate("#= (Time == null) ? ' ' : kendo.toString(Time, 'MM/dd/yyyy HH:mm:ss') #").Title("Time");

By applying the above code my problem gets solved but because of this filters in the kendo grid stop working. I want that filters should work inspite of having blank value for datetime field in the grid if datetime is not set.

2
votes

try this

columns.Bound(o => string.IsNullOrWhiteSpace(o.Time)?string.Empty:o.Time).Format("{0:MM/dd/yyyy HH:mm:ss}").Title("Time"); 

or use the column template to render the date.

<script type="text/x-kendo-template" id="TimeTemplate">
     # var date = time === null ? '': time ;#
    #=date#

</script>
1
votes
 columns.Bound(r => r.AssignedDate).ClientTemplate("#= AssignedDateFormat(data) #").Title("Assigned Dt").Width("40px"); 

function AssignedDateFormat(param) {
    var html;
    if (param.AssignedDate == null) {
        html = ""; 
    }
    else {
        html = kendo.toString(param.AssignedDate, 'MM/dd/yyyy');
    }

    return html;
}