Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show empty cell value for datetime field in Kendo grid?

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.

like image 683
kumawatp Avatar asked Dec 25 '22 17:12

kumawatp


2 Answers

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.

like image 153
kumawatp Avatar answered Apr 02 '23 01:04

kumawatp


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>
like image 23
Anto Subash Avatar answered Apr 02 '23 01:04

Anto Subash