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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Date is changing by few hours

Thread ID:

Created:

Updated:

Platform:

Replies:

141798 Jan 4,2019 01:51 PM UTC Jan 16,2019 08:40 AM UTC ASP.NET Core - EJ 2 7
loading
Tags: DataGrid
Vaidas
Asked On January 4, 2019 01:51 PM UTC

In Grid edit mode I change the date

<e-grid-column field="GaliojaNuo" headerText="Galioja nuo" width="100" editType="datepickeredit" format="yMd" edit="@(new { @params = new { type= "date",format = "yyyy-MM-dd" } })"></e-grid-column>

but to endpoint it is sending -2 hours



My Locale it is "lt-LT"

 ej.base.setCulture('lt');

Whats wrong?
And what I must to return from Update endpoint? Now I am getting empty result




Pavithra Subramaniyam [Syncfusion]
Replied On January 7, 2019 09:07 AM UTC

Hi Vaidas, 
 
Greetings from Syncfusion. 
 
Query: In Grid edit mode I change the date. <e-grid-column field="GaliojaNuo" headerText="Galioja nuo" width="100" editType="datepickeredit" format="yMd" edit="@(new { @params = new { type= "date",format = "yyyy-MM-dd" } })"></e-grid-column> but to endpoint it is sending -2 hours 
 
We have validated the reported issue and found that timezoneoffset is cause of this issue. TimezoneOffset will affect the converted string, when we stringify the date object. So we suggest you to use the following solution in actionBegin event of the Grid to resolve this issue. Please refer the following code example for your reference. 
 
[code example] 
 
... 
 
<div> 
    <ejs-grid id="Grid" locale="it" allowPaging="true" actionBegin="actionBegin" allowSorting="true" allowFiltering="true" height="273" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })"> 
        ... 
       <e-grid-columns> 
            ... 
       </e-grid-columns> 
    </ejs-grid> 
</div> 
 
<script> 
    function actionBegin(args) { 
        if (args.requestType == "save") { 
            var grid = document.getElementById("Grid").ej2_instances[0]; 
            var cols = grid.columns; 
            for (var i = 0; i < cols.length; i++) { 
                if (cols[i].type == "date") { 
                    var date = args.data[cols[i].field]; 
                    args.data[cols[i].field] = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMilliseconds())); 
                } 
            } 
        } 
    } 
</script> 
 
Please get back to us if you need further assistance. 
 
Regards, 
Pavithra S. 


Vaidas
Replied On January 10, 2019 08:36 PM UTC

It does not work.
I am getting the error SCRIPT5007: Unable to get property 'getFullYear' of undefined or null reference

Thavasianand Sankaranarayanan [Syncfusion]
Replied On January 11, 2019 09:18 AM UTC

Hi Vaidas 

Query : How can I resolve this script errorSCRIPT5007: Unable to get property 'getFullYear' of undefined or null reference” 

We have validated your requirement. But regrettably reported issue is not reproduced in our end. We suspect that you are not set the date type in the GaliojaNuo field and you are found getFullYear() from the date value in the string format. Since, we are already response that achieved your requirement using the ‘save’ action in the “actionBegin” event. In this event, we have applied the Date conversion for the GaliojaNuo field value before update the changes.  

Refer the below code example. 

    <ejs-grid id="Grid" toolbar="@(new List<string>() { "Add","Delete","Update", "Cancel" })" allowPaging="true" actionBegin="onActionBegin"> 
        <e-data-manager  json ="@ViewBag.datasource" adaptor="RemoteSaveAdaptor" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Delete" ></e-data-manager> 
        <e-grid-editSettings allowDeleting="true" allowEditing="true" allowAdding="true" showDeleteConfirmDialog="true"></e-grid-editSettings> 
        <e-grid-pagesettings pageCount="5"></e-grid-pagesettings> 
        <e-grid-columns> 
                     .    .    .   . 
            <e-grid-column field="OrderDate" headerText="Order Date" type="date" format="yMd" editType="datepickeredit" width="150"></e-grid-column> 
            <e-grid-column field="ShipCity" headerText="Ship City" width="170"></e-grid-column> 
            <e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column> 
        </e-grid-columns> 
    </ejs-grid> 
    <script> 
        function onActionBegin(args){         
            if (args.requestType == "save") { 
                var grid = document.getElementById("Grid").ej2_instances[0]; 
                var cols = grid.columns; 
                for (var i = 0; i < cols.length; i++) { 
                    if (cols[i].type == "date") { 
                        var date = args.data[cols[i].field];  // Here, Date conversion applied the OrderDate field value. 
                        args.data[cols[i].field] = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMilliseconds())); 
                    } 
                } 
            }  
        } 
    </script> 

We have prepared a sample and it can be downloadable from the below location. 


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

Regards, 
Thavasianand S. 


Vaidas
Replied On January 11, 2019 09:28 AM UTC

I am getting the same error still. date is good

 <e-grid-column field="GaliojaNuo" headerText="Galioja nuo" width="100" type="date" editType="datepickeredit" format="yMd" customFormat="@(new {type = "date", format = "yyyy-MM-dd" })" edit="@(new { @params = new { type= "date",format = "yyyy-MM-dd"  } })"></e-grid-column>
        <e-grid-column field="GaliojaIki" headerText="Galioja iki"  type="date" editType="datepickeredit" format="yMd" width="100" customFormat="@(new {type = "date", format = "yyyy-MM-dd" })" edit="@(new { @params = new { type= "date",format = "yyyy-MM-dd" } })"></e-grid-column>

function actionBegin(args) {
        if (args.requestType == "save") {
            var grid = document.getElementById("Grid").ej2_instances[0];
            var cols = grid.columns;
            for (var i = 0; i < cols.length; i++) {
                if (cols[i].type == "date") {
                    var date = args.data[cols[i].field];
                    alert(date);
                    args.data[cols[i].field] = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMilliseconds()));
                }
            }
        }
    } 



Thavasianand Sankaranarayanan [Syncfusion]
Replied On January 16, 2019 07:05 AM UTC

Hi Vaidas, 

We have checked the reported issue but the issue is not reproduced in our end. We suspect that the script error is due to the existing cache so please clear the cache and delete the auto generated folders (bin and obj folders) and rebuild the project to resolve this issue. 

Please get back to us if you need further assistance. 

Regards, 
Thavasianand S. 


Vaidas
Replied On January 16, 2019 08:18 AM UTC

OK. Problem is solved

Thavasianand Sankaranarayanan [Syncfusion]
Replied On January 16, 2019 08:40 AM UTC

Hi Vaidas, 
 
We are happy that the problem has been solved. 
 
Please get back to us if you need any further assistance.  
                          
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

;