Blazor WebAssembly app: pass in-memory data into FlexmonsterComponent

Answered
Anton Ihnatenko asked on March 23, 2023

We have a Blazor WebAssembly application which generates some amount of data on the client side. We store this data in CSV format, in memory, as a string named "reportData".
Then we pass this data to the FlexmonsterComponent like this:

var report = new Flexmonster.Blazor.Report
{
    DataSource = new Flexmonster.Blazor.DataSource
    {
        Data = reportData.Split('\n'),//OR like this Data = new object[]{ reports.result.ReportData },
        Type = "csv"
    }
};

await _flex.SetReport(report);

Anyway, it looks like FlexmonsterComponent treats each character as a separate value, despite specifying Type as "csv".
Please, advise how to correctly pass in-memory "csv" data to FlexmonsterComponent.

4 answers

Public
Maksym Diachenko Maksym Diachenko Flexmonster March 24, 2023

Hello, Anton!

Thank you for writing to us.

Please note that the DataSource.Data is a property to set JSON data if it is already on the page. Flexmonster supports two formats of JSON data - an array of objects and an array of arrays. We recommend converting your inline CSV to an array of arrays since such a format resembles the CSV structure. You are welcome to check the example function that can be used for conversion:

private static object[] csvStringToArrayOfArrays(String csvString, char separator)
{
    List<object[]> result = new List<object[]>();
    string[] csvLines = csvString.Split('\n');
    foreach(string line in csvLines) {
        string[] tokens = line.Split(separator);
        result.Add(tokens);
    }
    return result.ToArray();
}

Please let us know if such an approach would work for you.

Best Regards,
Maksym

Public
Maksym Diachenko Maksym Diachenko Flexmonster April 11, 2023

Hello, Anton!

Hope you are doing well.
Our team is wondering if you tried using the suggested approach for converting the CSV string to JSON data.
Please let us know if this solution works for you.

Best Regards,
Maksym

Public
Anton Ihnatenko April 11, 2023

Hello Maksym,
Works like a charm.
Thank you for your assistance.

Public
Maksym Diachenko Maksym Diachenko Flexmonster April 12, 2023

Hi, Anton!

Thank you for your feedback.
We are glad to hear that the proposed solution worked for you.
Feel free to contact us if any other questions arise.

Best Regards,
Maksym

Please login or Register to Submit Answer