Declined
Last Updated: 16 Apr 2025 11:28 by ADMIN
Andreas
Created on: 01 Apr 2025 08:16
Category: UI for Blazor
Type: Bug Report
0
Do not replace '/' in custom DateTime format in GridColumn filter dialog

Hi there,

I have a TelerikGrid with a DateTime column. I use a custom FilterEditorFormat which is localizable depending on the user settings, e.g. "dd/MM/yyy HH:mm:ss". Unfortunately, any '/' in the date component is always replaced by the current culture's DateSeparator. Using any other separator works, e.g. '-'. 

Expectation: Use the FilterEditorFormat without modification, unless it's a standard format string like "g" or "D".

I already traced it down to Telerik's FormatHelper class and it seems like a quick fix.

Steps to reproduce:

  • Create a TelerikGrid with a DateTime column and a FilterEditorFormat as shown above.
  • If required, change the DateSeparator to anything else but '/'.
  • Run and open the filter dialog

Please let me know if you need any additional information.

Best regards

Andreas

5 comments
ADMIN
Tsvetomir
Posted on: 16 Apr 2025 11:28

Hi Andreas,

Thank you for sharing your insights and the attached project. I understand the complexity you're facing with the culture context when updating components from background threads. It's great to hear that your team is considering a change in the localization mechanism.

Here's a brief overview of what you can consider. Please note that these questions about the localization fall outside the scope of our official support services, because has no direct relation with the product. The responses provided are based on my understanding and assumptions and may not reflect complete accuracy.

  • Culture Management - Since CultureInfo.CurrentCulture and CultureInfo.CurrentUICulture are AsyncLocal, they retains its values across asynchronous calls. To ensure the correct culture is used, you might need to explicitly set the culture at the beginning of each operation that requires it. This can be done by setting CultureInfo.CurrentCulture and CultureInfo.CurrentUICulture to the desired culture before calling InvokeAsync(StateHasChanged).

  • Custom Implementation - If you have a custom solution that works well, as shown in your prototype, it might be worth integrating it into your existing system. This could involve wrapping your culture setting logic in a helper function or service that ensures the correct culture is set whenever necessary.

    Additionally, I just want to point-out that this ticket is a public thread, so the whole community can benefit from it, if needed. Your cooperation is much appreciated.

      Regards,
      Tsvetomir
      Progress Telerik

      Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

      Andreas
      Posted on: 11 Apr 2025 12:27

      Hi Tsvetomir,

      thanks for your feedback. We really appreciate you take these requests seriously.

      As team we already agreed on changing our localization mechanism. Updating the status do declined is absolutely fine.

      Regarding localization, a simple InvokeAsync(StateHasChanged) is not enough. CultureInfo.Current(UI)Culture is AsyncLocal, so it remains the same instance within an async context. When await InvokeAsync(StateHasChanged) is called from a BackgroundService callback, the async local context is inherited, so the rendering will happen with the wrong culture. 

      If you are interested you can check out the attached project which highlights the problem. There also is a simple solution which is also prototpyed in the project.

       

      Best regards!

      Andreas

      Attached Files:
      ADMIN
      Tsvetomir
      Posted on: 11 Apr 2025 08:06

      Hi Andreas,

      Thank you for coming back with feedback.

      I've discussed the pointed implementation in the FormatHelper with the team. As a result, I can briefly inform you that formatting numbers, dates, and times according to the user's cultural settings is essential for clarity, accuracy, and a positive user experience. It helps prevent misinterpretation (e.g., date or decimal confusion) and makes users feel more comfortable by presenting information in a familiar format. This practice is a widely accepted convention in internationalization and localization, supported by most modern development frameworks. We follow these conventions that are widely accepted as standard practice:

      I hope the above provides you more clarity around the implementation around the FormatHelper. With that being said, I'm changing the status of the item as "Declined"

      On the other hand, to update components from background threads is recommended to use InvokeAsync(StateHasChanged). You can gather, more information about that approach in this Blazor University article - https://blazor-university.com/components/multi-threaded-rendering/invokeasync/

      Regards,
      Tsvetomir
      Progress Telerik

      Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

      Andreas
      Posted on: 08 Apr 2025 07:56

      Hi Tsvetomir,

      Our components need to be updated on events that are raised by BackgroundServices, MassTransit consumers and so on. To achieve this, we currently use static standard .NET events. Our components subscribe to these events and update their content. As the event handlers get called from a central background service, the culture is not the one from the user but the default culture of the system. Hence, we needed a way to do localization that does not rely on the CultureInfo.Current(UI)Culture, and basically implemented our own layer.

      This has worked with each and every component until I stumbled across the custom formats in the grid due to the (imho) unexpected behaviour I pointed out.

      I guess I can find a workaround, but I do not understand why the FormatHelper is implemented like this.

       

      Btw, do you know if there is a best practice on how to update components from background threads with full localization support? The approach described above was already implemented when I started, and it does not feel appropriate...

       

      Best regards

      Andreas

      ADMIN
      Tsvetomir
      Posted on: 07 Apr 2025 06:23

      Hi Andreas,

      After a recent evaluation of your request with the Blazor team. We have the following questions regarding your scenario:

      • Why do you want to display a format that will be different from the actual culture?
      • Why do you need to specific custom format only in the Grid?
      • Why don't you use some of the standard format specifiers?

      The current implementation of the FormatHelper is focused on complying with the culture of the user. Customizing such a behavior will lead to a discrepancy between the Grid component and the other date-related components in the application. If you have such an option, the user's culture will be ignored only in the Grid, which will lead to a difference with other dates in the application.

      I hope the above information sheds some light on your scenario. I'm changing the status of the item to "Need More Info" and look forward to your reply.

      Regards,
      Tsvetomir
      Progress Telerik

      Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!