samedi 16 juillet 2022

What data model to use for tables in Blazor

I am building a .Net 6 Blazor web app. I needs to display lots of html tables with data. For example I need tables that look like this:

       |Jul 17 | Jul 16  | Jul 15
--------------------------------- . . .
Hour 1 | 11.213 | 123.23 | 123.54
Hour 2 | 12.234 | 234.45 | 54.34
.
.
.

Code:

I want to display a lot of tabular data and I would like to be able to compute new tabular data based on the ones I already have, like calculating averages of an existing "table" models rows.

I considered having a data structure like this:

public class DataTable
{
    public DataTable(Dictionary<string, Dictionary<string, decimal?>>? values)
    {
        Values = values ?? new Dictionary<string, Dictionary<string, decimal?>>();
    }

    public Dictionary<string, Dictionary<string, decimal?>>? Values { get; set; }
}

Questions:

  • Is this a good approach?
  • How can I store optional row and column headers?
  • What if I want to create a table with strings? I can't restrict extension methods for a generic class to "number" types, so it seems to no be good design.

Aucun commentaire:

Enregistrer un commentaire