We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Date error

Good Night,

I'm trying to show a DateTime field on grid, but when I refresh the grid, it's hide all DateTime fields or return Invalid Date.
See my code next:

<div id="divGrid" class="row">
    <div class="col-md-12">
 
        @Html.EJS().Grid("Index").DataSource((IEnumerable<object>)ViewBag.dataSource).Load("load").AllowResizing().AllowPaging().PageSettings(page => { page.PageSize(100); }).AllowSorting().AllowFiltering().FilterSettings(filter => { filter.Type(Syncfusion.EJ2.Grids.FilterType.Excel); }).AllowGrouping().Columns(col =>
   {
       col.Field("MensagemId").IsPrimaryKey(true).IsIdentity(true).Visible(false).Add();
       col.Field("type").HeaderText("Tipo").HeaderTextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Width(30).Add();
       col.Field("ConteudoASCII").HeaderText("Mensagem").HeaderTextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).Add();
 
 
       col.Field("DataRegistro").HeaderText("Data Registro").HeaderTextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Width(60).Add();
       col.Field("DataEnvio").HeaderText("Data Envio").HeaderTextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Width(60).Add();
   }).SearchSettings(search => { search.Operator("contains").IgnoreCase(true).IgnoreAccent(true); }).Toolbar(new List<string>() { "Search" }).Locale("en-US").RecordDoubleClick("LoadRegistro").Render()
 
    </div>
</div>
 
 
 
@section Scripts {
 
 
    <script type="text/javascript" charset="UTF-8">
 
        //ej2.parse = false;

        function load(args) {
            this.columns[3].format = { type: 'date', format: 'dd/MM/yyyy HH:mm' };
            this.columns[4].format = { type: 'date', format: 'dd/MM/yyyy HH:mm' };
        }
 
        //REFRESH DEAFULT GRID
        function UpdateGrid() {
 
            var grid = document.getElementById("Index").ej2_instances[0]; // Grid instance
            var ajax = new ej.base.Ajax('/NotificacaoMensagem/DataSource', 'GET');
            ajax.send();
            ajax.onSuccess = function (data) {
                grid.dataSource = JSON.parse(data).result; LoadingOff();
                alert("1");
            };
        }

public partial class VNotificacao_GridMensagem
    {
        public int MensagemId { get; set; }
        public System.Guid MensagemUnique { get; set; }
        public string ConteudoASCII { get; set; }
        public string ConteudoBase64 { get; set; }
        public string fname { get; set; }
        public string caption { get; set; }
        public int type { get; set; }
        public System.DateTime DataRegistro { get; set; }
        public bool Pergunta { get; set; }
        public Nullable<System.DateTime> LimiteResposta { get; set; }
        public Nullable<System.DateTime> DataEnvio { get; set; }
        public Nullable<System.DateTime> DataExclusao { get; set; }
    }

public JsonResult DataSource()

               var Dados = cactusDBEntities.VNotificacao_GridMensagem.ToList();
 
               int count = Dados.Cast<VNotificacao_GridMensagem> ().Count();
 
               return Json(new { result = Dados, count = count }, JsonRequestBehavior.AllowGet);
 }

Attachment: e_92b5310c.zip

3 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team July 29, 2019 08:39 AM UTC

Hi Fillipe, 

Thanks for contacting Syncfusion support. 

We suggest you to parse the Grid data by using the “DataUtil.parse.parseJson” method to overcome the reported behavior. Please refer to the below code example for more information. 

[index.cshtml] 
@Html.EJS().Grid("Index").Load("load").Columns(col => 
{ 
    col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").Add(); 
    col.Field("OrderDate").HeaderText("Data Registro").HeaderTextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Width(60).Add(); 
}).AllowPaging().ActionFailure("fail").Render() 
 
 
<script> 
 
    function load(args) { 
 
        this.columns[1].format = { type: 'date', format: 'dd/MM/yyyy HH:mm' }; 
 
        var grid = document.getElementById("Index").ej2_instances[0]; // Grid instance 
 
        var result = JSON.parse(data).result; // data is a string contains result and count 
 
        grid.dataSource = ej.data.DataUtil.parse.parseJson(result); 
    }    
 </script> 

Please get back to us if you need any further assistance on this. 

Regards, 
Thavasianand S. 



FB Fillipe Barbosa August 5, 2019 05:32 PM UTC

Hi, Thavasianand,
Thank you for your help, the grid is working perfect now.



TS Thavasianand Sankaranarayanan Syncfusion Team August 6, 2019 08:40 AM UTC

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


Loader.
Live Chat Icon For mobile
Up arrow icon