Need a special offer?Find out if your project fits.
+

Set null dates to blank in Blazor wasm

Answered
Brent Minder asked on March 7, 2024
  1. Null dates are showing as "Invalid date", and we just want an empty string.
  2. Null strings are showing as "(blank)", and we just want an empty string.

Is there a c# way to set these? If not, how to set them the non c# way? I've seen the samples for localization, but not really for blazor.
I've created a "wwwroot\flexmonster-localization.json" file like this:

{
"global": {
"localization": {
"grid": {
"blankMember": " ",
"dateInvalidCaption": " "
}
}
}
}

And tried to invoke it like this:

await JSRuntime.InvokeVoidAsync("setFlexmonsterLocalization", FlexPivot, "/flexmonster-localization.json");

In a component like this:

<FlexmonsterComponent @ref="FlexPivot" />

And get this runtime error:

Unhandled exception rendering component: Cannot read properties of undefined (reading 'setLocalization')
TypeError: Cannot read properties of undefined (reading 'setLocalization')
at window.setFlexmonsterLocalization (https://localhost:44301/js/FlexmonsterTweaks.js?v=1709851561109:12:29)
at https://localhost:44301/_framework/blazor.webassembly.js:1:3337

 
 
 
 

5 answers

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster March 8, 2024

Hello, Brent!
 
Thank you for reaching out to us.
 
Kindly note that to set the localization for Flexmonster in Blazor, you need to specify the URL of the localization file. As the file is located in the wwwroot folder, it is accessible from the client side on https://yourdomain/flexmonster-localization.json, so you can specify the URL in the report as follows:

report = new Report()
{
    Localization = "/flexmonster-localization.json"
};

Please note that there is no separate API call to set the localization, so you can set it while creating or changing the Report.
 
Regarding the content of the flexmonster-localization.json, it should look as follows:

{
  "grid": {
    "blankMember": " ",
    "dateInvalidCaption": " "
  }
}

 
Please let us know if the suggested approach works well for you.
Looking forward to hearing from you.
 
Kind regards,
Soloimiia

Public
Brent Minder March 8, 2024

That works! Thank you!

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster March 8, 2024

Hello, Brent!

Thank you for your feedback.

We are glad to hear the suggested approach works well for you.

Do not hesitate to contact us if any other questions arise.

Best regards,
Solomiia

Public
Brent Minder March 8, 2024

This c# based solution seems to work for all FM reports:

dynamic localization = new System.Dynamic.ExpandoObject();
dynamic grid = new System.Dynamic.ExpandoObject();
grid.blankMember = "";
grid.dateInvalidCaption = "";
localization.grid = grid;
report.Localization = localization;
Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster March 11, 2024

Hello, Brent!

Thank you for sharing your approach of changing localization in Blazor.
We are glad that everything works well now.

Feel free to reach out in case of any other questions.

Kind regards,
Solomiia

Please login or Register to Submit Answer