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
close icon

Datepickeredit value in datagrid not correct

Hi,

I have a "datepickeredit" in datagrid.
But when the value is passed to the database, the value is minus 8 hours.
Is it because of timezone on the PC ?

5 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team June 3, 2019 09:03 AM UTC

Hi Mohd, 

Greetings from Syncfusion support. 

By default, while using remote data it send(response) the date object in UTC format and it does not converted to local time zone so we request you to apply the serverTimezoneOffset as below to resolve the reported problem. 


<script> 
    ej.data.DataUtil.serverTimezoneOffset = (2 * (new Date().getTimezoneOffset() / 60));   //Set the servertimezoneoffset 
</script> 
 
<ejs-grid id="Grid" allowPaging="true" toolbar="@(new List<string>() {"Add", "Edit", "Update", "Delete" })"> 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings> 
    <e-data-manager url="/Home/UrlDataSource" adaptor="UrlAdaptor" insertUrl="/Home/Insert" , updateUrl="/Home/Update" removeUrl="/Home/Remove"></e-data-manager> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column> 
        ... 
   </e-grid-columns> 
</ejs-grid> 

Please find the below sample for more information. 


Please get back to us if you need further assistance 
 
Regards, 
Thavasianand S. 



MM Mohd Mohaimin Zakaria June 4, 2019 01:36 AM UTC

Hi,

The solution you give is solve in view for the datepickeredit.
But when the data is passed to the entity and save to database, the value is still minus 8 hours.

Same with your example. When I debug, the date still minus 8 hours.

        public IActionResult Update([FromBody]CRUDModel<Orders> value)
        {
            var data = order.Where(or => or.OrderID == value.Value.OrderID).FirstOrDefault();
            if(data != null)
            {
                data.OrderID = value.Value.OrderID;
                data.CustomerID = value.Value.CustomerID;
                data.EmployeeID = value.Value.EmployeeID;
                data.OrderDate = value.Value.OrderDate;
                data.ShipCity = value.Value.ShipCity;
                data.Freight = value.Value.Freight;
            }
            return Json(value.Value);
        }




TS Thavasianand Sankaranarayanan Syncfusion Team June 4, 2019 06:37 AM UTC

Hi Mohd, 
 
Please use the below code example to modify the date column value while saving the data in server end.  
 
  
 
 
function actionBegin(args) {  
            if (args.requestType === 'save') {  
                var grid = (document.getElementsByClassName("e-grid")[0] as any).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()));  
                    }  
                }   
            }  
        }  
     

Please get back to us if you need further assistance. 

Regards, 
Thavasianand S. 



MM Mohd Mohaimin Zakaria June 11, 2019 12:44 AM UTC

Could you please include the above code in your sample.
I still have problem with the date using your solution.
Thank you.


TS Thavasianand Sankaranarayanan Syncfusion Team June 11, 2019 02:16 PM UTC

Hi Mohd, 

As per your suggestion we have prepared a sample and it can be downloadable from the below location. 


Regards, 
Thavasianand S. 


Loader.
Live Chat Icon For mobile
Up arrow icon