Hey guys!
This gonna be a thread with some more questions hanging together, so take your time :D
We wanted to ask you what you think is the smartest way to display utc times as local user time in a Grid?
Our current way is pretty clunky, and we just had an issue because you updated the WhereFilter from the DataRequestManager, because we have a CustomAdaptor as SFDataManager. Formerly the value of a WhereFilter was of type object and we could check the type of the object for further operations. Since one of the last updates the value is of type JsonElement. e.g. DateTime values have JsonElemen.ValueKind.String which is no indicator.
We found a workaround with a regex expression. Is there an overview for breaking changes like these? We were not prepared for this because we did not see anything about this.
-
What we curretnly do:
In our application we use grids displaying our database entities. To avoid an overhead with every edit we use DTOs (DataTransferObjects) and map our Database entities to them with the AutoMapper. So our queries run directly on the data base filtering the entities but we only display the DTOs . Our DTOs with time entries like a "StartDate" date have properties named "StartDateUserTime" - in the grid we only use the user time properties like:
<GridColumn HeaderText="Start Date" Field="@nameof(ExampleDto.StartDateUserTime)"></GridColumn>
--> currently we fill those columns in our CustomAdaptor in the Read method. We check if it is a user time column by the name, and take the according utc field and translate them to the current user time. For this we have now to check if the value of the DataRequest.WhereFilter is of type JsonElement and it has ValueKind string and compare the string with a regex expression for Utc DateTime strings to check if it is a date value in order to convert them to user time if needed. We feel like there should be a smarter way because it is a very common case that date times in databases are saved in UTC and people want to display them in user time.
Is there anything already implemented doing that and we don't know about that? It is kinda fragile how we're doing it. If you change something like you did we have to refactor the whole DateTime part of our CustomAdapter.
-
Additionally we like to display the date values with and without date time, so the people can decide which column they want to display. Again for this we have another property in our DTOs named "StartDateUserTimeWithoutDateTime" because we can't use the same Field name only using a different format, because it causes issues by saving and filtering the entities.
Is there a smart way to display one field with and without datetime in 2 different columns?
-
As you see we have a load of questions depending on the DateTime conversion to user time and our current implementation does not feel correct. Could be great if you have any ideas or already implemented functions for this we don't know.
Thanks and best regards
Patrick
Hi,
Personally I use DataAdapter where within the ReadAsync function i capture the datas then I convert UTC dates to Locale in just few lines of code then it works
|
<GridColumn Field=@nameof(Order.OrderDate) HeaderText="OrderDate" TextAlign="TextAlign.Right" Width="120">
<Template>
@{
var contextval = context as Order;
<div>@contextval.OrderDate.ToString("MM/dd/yyyy")</div>
<div>@contextval.OrderDate.ToString("MM/dd/yyyy hh:mm tt")</div>
}
</Template>
</GridColumn>
|
Hi Syncfusion,
Regarding your response to Gerome, namely:
Hi Gerald,
Greetings from Syncfusion support.
Query: “How does the above support the conversion of UTC to the local time zone? Can you provide sample code that demonstrates this functionality? Thanks in advance.”
We have checked your query and we would like to inform that by default in DataGrid we will convert the Utc time to local time and display it in the Grid. In the below sample we have used northwind database and we could see that it has Utc time on OrderDate column but when we display it on DataGrid it will display in local time format (i.e. + 5.30 hrs.). This conversion will take place in Grid internally. Kindly check the below sample and screen snip for your reference.
Sample: https://blazor.syncfusion.com/documentation/data/adaptors#odatav4-adaptor
|
{"@odata.context":https://services.odata.org/V4/Northwind/Northwind.svc/$metadata#Orders,"value":[{"OrderID":10248, "CustomerID":"VINET","EmployeeID":5,"OrderDate":"1996-07-04T00:00:00Z","RequiredDate":"1996-08-01T00:00:00Z","ShippedDate":"1996-07-16T00:00:00Z","ShipVia":3,"Freight":32.3800, "ShipName":"Vins et alcools Chevalier","ShipAddress":"59 rue de l'Abbaye","ShipCity":"Reims","ShipRegion":null,"ShipPostalCode":"51100","ShipCountry":"France"},
|
|
|
Kindly get back to us if you have further queries.
Regards,
Monisha
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Hi Monisha,
Thanks for your response. I cannot seem to find a link to the sample code. This item (part of your response) was linked to another part of the website - I believe it may have been an accident?
>> Sample: https://blazor.syncfusion.com/documentation/data/adaptors#odatav4-adaptor
Gerald.
Hi Gerald,
Sorry for the inconvenience caused.
We have prepared an sample as per your request. Kindly check the attached sample.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorApp1-1241529134.zip
Also we would like to inform that we have documented this topic in our documentation. So we have shared it for an additional reference.
Documentation: https://blazor.syncfusion.com/documentation/data/adaptors#odatav4-adaptor
Please get back to us if you have further queries.
Regards,
Monisha
Hi Monisha
Thanks for your response.
I understand from your earlier message that the UTC -> local time conversion is automatic. I reviewed the data in the database vs. what is in the grid, and the UTC time in the database is +1 hours from the grid time. It should be +5 hours for the local time zone. How do we check which timezone is being used by the grid to confirm it is sourced correctly? Thanks in advance.
Gerald
Hi Gerald,
Thanks for the update.
We would like to inform that by default the Grid converts UTC time to local time zone. We suspect that your Grid shows +1hr lesser time when compare to database time. kindly share the below details to validate the issue further at our end.
The above-requested details will be helpful for us to validate the reported query at our end and provide the solution as early as possible.
Regards,
Monisha