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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Date error

Thread ID:

Created:

Updated:

Platform:

Replies:

146256 Jul 27,2019 06:54 AM UTC Aug 6,2019 08:40 AM UTC ASP.NET MVC - EJ 2 3
loading
Tags: Grid
Fillipe Barbosa
Asked On July 27, 2019 06:54 AM UTC

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

Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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. 


Fillipe Barbosa
Replied On August 5, 2019 05:32 PM UTC

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


Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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.  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon