i am quite new to syncfusion and trying to use the sfgrid to display generic data from List<KeyValuePair<string,string>>.
Here is the sourcecode but i have no glue how to render the row data. I already did to google a solution, searched the forum but did not find a solution.
I have a table with viewcolumns and rows. Rows are of type KeyValuePair<string,string>, viewcolumns represent the columns of the grid and added dynamically.
Thanks for some hints.
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Inputs
<SfGrid DataSource="@ds.Rows" @ref="TableGrid">
<GridColumns>
</GridColumns>
</SfGrid>
@code{
SfGrid<TableRow> TableGrid;
public Table ds = null;
protected override Task OnInitializedAsync()
{
ds = new Table();
ds.ViewColumns.Add(new ViewColumn { Headertext = "First Name", Position = 1, Schemaname = "firstname" });
ds.ViewColumns.Add(new ViewColumn { Headertext = "Last Name", Position = 2, Schemaname = "lastname" });
ds.ViewColumns.Add(new ViewColumn { Headertext = "Day Of Birth", Position = 3, Schemaname = "birthdate" });
var Row = new TableRow();
Row.RowData.Add(new KeyValuePair<string, string>("firstname", "Martin"));
Row.RowData.Add(new KeyValuePair<string, string>("lastname", "Muster"));
Row.RowData.Add(new KeyValuePair<string, string>("birthdate", "04.02.1988"));
ds.Rows.Add(Row);
Row = new TableRow();
Row.RowData.Add(new KeyValuePair<string, string>("firstname", "Michael"));
Row.RowData.Add(new KeyValuePair<string, string>("lastname", "Meier"));
Row.RowData.Add(new KeyValuePair<string, string>("birthdate", "04.05.1968"));
ds.Rows.Add(Row);
Row = new TableRow();
Row.RowData.Add(new KeyValuePair<string, string>("firstname", "Hans"));
Row.RowData.Add(new KeyValuePair<string, string>("lastname", "Muster"));
Row.RowData.Add(new KeyValuePair<string, string>("birthdate", "26.02.1990"));
ds.Rows.Add(Row);
Row = new TableRow();
Row.RowData.Add(new KeyValuePair<string, string>("firstname", "Fritz"));
Row.RowData.Add(new KeyValuePair<string, string>("lastname", "Müller"));
Row.RowData.Add(new KeyValuePair<string, string>("birthdate", "26.05.1990"));
ds.Rows.Add(Row);
return base.OnInitializedAsync();
}
protected override Task OnAfterRenderAsync(bool firstRender)
{
if ( firstRender)
{
foreach ( var v in ds.ViewColumns)
{
TableGrid.Columns.Add(new GridColumn { HeaderText = v.Headertext });
}
}
return base.OnAfterRenderAsync(firstRender);
}
public class Table
{
public List<TableRow> Rows;
public List<ViewColumn> ViewColumns;
public Table()
{
Rows = new List<TableRow>();
ViewColumns = new List<ViewColumn>();
}
}
public class TableRow
{
public List<KeyValuePair<string, string>> RowData;
public TableRow()
{
RowData = new List<KeyValuePair<string, string>>();
}
}
public class ViewColumn
{
public int Position { get; set; }
public string Headertext { get; set; }
public string Schemaname { get; set; }
}
}