Formatting DateTime column from a nullable property?

I have a grid that is bound to a list (IEnumerable<T>) and displays a number of columns including a nullable DateTime property.

The column displaying the nullable DateTime is set up as follows:
<e-grid-column field="CompletionDate" headerText="Completed" format="dd-MMM-yy"></e-grid-column>

This is the corresponding property in the model:

public DateTime? CompletionDate { get; set; }

This has worked correctly when using non a non nullable DateTime (there is another column in the same grid set up in this way) but no formatting is applied for the nullable DateTime (e.g. "Fri Feb 14 2020 00:00:00 GMT+0000 (Greenwich Mean Time)")

Is there a way of applying formatting to a nullable column?

3 Replies

DR Dhivya Rajendran Syncfusion Team February 24, 2020 11:41 AM UTC

Hi Daniel, 

Greetings from syncfusion support. 
Query : Formatting DateTime column from a nullable property? 
From your query, we could see that you can’t able to apply the format for the nullable datetime column. By default, If we are not specified type property for columns in the grid then we have set the column’s type based on the first value of the data source. If the date time column contains null value for the first cell, the column type is set to be null so that the format is not applied properly. 

To avoid  the reported problem by setting type as date for date columns in the grid. Please refer the below code example and sample for more information. 
 


<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" height="273" toolbar="@(new List<string>() { "Add", "Edit", "Delete","Update","Cancel" })"> 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" template='#dialogtemplate'></e-grid-editSettings> 
    <e-grid-columns> 
        --------- 
        <e-grid-column field="OrderDate" headerText="Order Date" type="date" format='dd-MMM-yyyy' textAlign="Right" width="140"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 


Please get back to us if you need further assistance. 

Regards, 
R.Dhivya 



DA Daniel March 7, 2020 08:42 AM UTC

That worked perfectly, thanks!


MS Magesh Sabapathi Syncfusion Team March 10, 2020 05:38 AM UTC

Hi Daniel, 

We are happy to hear that your issue has been resolved. 

Please get back to us if you need further assistance 

Regards 
Magesh 
 


Loader.
Up arrow icon