Hi,
I know that to access a Radzen Blazor component (or any Blazor component)
you need to use the @ref attribute.
Again I know how it works.
Example:
<RadzenGrid TItem="Customer" @ref="myGrid" />
<RadzenTextBox @ref="myTextBox" />
@code {
RadzenGrid<Customer> myGrid;
RadzenTextBox myTextBox;
}
How can I refer to my radzen grid if I don't use EF databinding but dynamic data ?
My data is a IDictionary<string, object>.
Hereunder some lines of code to better explain what I'm asking for:
<RadzenDataGrid @ref="elencoProdotti" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterMode="FilterMode.Advanced"
AllowPaging="true" PageSize="5" AllowSorting="true" Data="@data" TItem="IDictionary<string, object>" LoadData="@LoadData" IsLoading="@isLoading" Count="@count" >
<Columns>
<RadzenDataGridColumn TItem="IDictionary<string, object>" Property="id_prodotto" Title="id_prodotto" Type="typeof(int)">
<Template>
@context["id_prodotto"]
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn Width="100px" TItem="IDictionary<string, object>" Property="inventario" Title="Inv">
<Template>
@context["inventario"]
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="IDictionary<string, object>" Property="descrizione" Title="descrizione" Type="typeof(string)">
<Template>
@context["descrizione"]
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="IDictionary<string, object>" Property="fornitore" Title="fornitore" Type="typeof(string)">
<Template>
@context["fornitore"]
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="IDictionary<string, object>" Property="" Title="" Type="typeof(string)">
<Template>
<RadzenButton ButtonStyle="ButtonStyle.Info" Icon="help" Click=@(() => OpenOrder(Convert.ToInt16(@context["id_prodotto"]))) Text="@context["id_prodotto"].ToString()" />
</Template>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
@code {
MySqlDataAccessLayer dal = new MySqlDataAccessLayer();
funzioni fz = new funzioni();
DataTable dt = new DataTable();
IEnumerable<IDictionary<string, object>> data;
bool isLoading;
int count;
RadzenGrid<IDictionary<string, object>> elencoProdotti; (<-- doesn't work...)
protected override void OnInitialized()
{
elencoProdotti.Reload();
}
async Task LoadData(LoadDataArgs args)
{
isLoading = true;
string sql = "select id_prodotto,inventario, descrizione, fornitore from tb_prodotti";
dt = dal.PopolaDataTable(CommandType.Text, sql);
Console.WriteLine(dt.Rows.Count);
var columns = dt.Columns.Cast<DataColumn>();
data = dt.AsEnumerable().Select(dataRow => columns.Select(column =>
new { Column = column.ColumnName, Value = dataRow[column] })
.ToDictionary(data => data.Column, data => data.Value));
count = dt.Rows.Count;
isLoading = false;
}
}
Thanks in advance!