Format and Formatter methods on columns don't work

Hello

I have a grid with a DateTime type column.

When I define column like this:
.Columns(col =>
 {
   col.Field("OrderDate").Format("dd.MM.yyyy.").Add();
})

or
.Columns(col =>
 {
   col.Field("OrderDate").Formatter("onFormat").Add();
})

no data is shown in the Grid.
Do Format and/or Formatter work and how am I supposed to use them to display DateTime field in the grid?

Thanks, Tom

5 Replies

VA Venkatesh Ayothi Raman Syncfusion Team October 26, 2018 06:10 AM UTC

Hi Tomislav, 

Thanks for using Syncfusion products. 


In Essential JavaScript 2 Grid, if you use the default CLDR data-time format then you can directly use the format string in the column’s format property. Since we have used the CLDR data for number and date format. Please refer to the following help documentation, 

For your requirement, we can set the custom format using Grid load event. Please refer to the below code example. 

@Html.EJS().Grid("FlatGrid").DataSource((IEnumerable<object>)ViewBag.dataSource) 
.Columns(col =>  
        {  
          ...  
                      
 }).Load("load").Render()  
  
<script>  
    function load(args) {  
        //Set the dateTime format for the date column “OrderDate” based on index  
        this.columns[4].format = { type: 'date', format: 'dd/MM/yyyy' };  
    }  
 
 
</script>  



Note: Above code example show the date as 26/10/2018. If you want to show the date as 26.10.2018 then we can set the date format object like as follows, 
<script>  
    function load(args) {  
        //Set the dateTime format for the date column “OrderDate” based on index  
        this.columns[4].format = { type: 'date', format: 'dd.MM.yyyy' };  
    }  
</script>  


Please let us know if you have any further assistance on this. 

 
Regards,
Venkatesh Ayothiraman. 



TT Tomislav Tustonic October 26, 2018 11:52 AM UTC

Hello

Hm, from this response it seems that the Format and Formatter methods are either useless or complete prevent grid from loading.

I looked at the documentation here
https://ej2.syncfusion.com/aspnetmvc/documentation/grid/columns.html#format
and tried this:
.Format("yMd")
which doesn't do anything,
and this:
Format(new { type = "date", format = "dd/MM/yyyy" }).
which can't be used, since Format only accept strings

You should either remove the misinformation from the documentation:
https://ej2.syncfusion.com/aspnetmvc/documentation/grid/columns.html#format
or fix the Format method to work as documented.

Thanks,
Tom



VA Venkatesh Ayothi Raman Syncfusion Team October 29, 2018 07:20 AM UTC

Hi Tomislav, 
 
 
Sorry for the inconvenience caused. 
 
Yes, column format Razor code accepts string type only and we can give the CLDR date format directly in Grid like ‘yMd’. If we are using custom date format, then we should give in load event of grid as we have provided in last update. Please refer to the following  
 
We have considered this “Modify the custom Date format code example” as documentation task and it will be on live upcoming release. Until we appreciate your patience. 
 
 
Regards,
Venkatesh Ayothiraman. 



AP Apostolos August 18, 2019 08:45 AM UTC

18/8/2019 and using the .Format() breaks the table.
Your provided solution works.


TS Thavasianand Sankaranarayanan Syncfusion Team August 19, 2019 06:43 AM UTC

Hi Apostolos, 
 
Thanks for your update. 
 
We are happy that the problem has been resolved at your end. 
 
Regards, 
Thavasianand S.  


Loader.
Up arrow icon