hekra
February 18, 2021, 9:54am
1
Hey hey, back with another question as the first one was answered perfectly!
I'm trying to build a DataGrid Master Detail Hierarchy on demand.
I can expand the rows, but they are always empty.
List<itemList> itemList;
int pageSize = 15;
RadzenGrid<itemList> grid;
protected override async Task OnInitializedAsync()
{
string sql = "SELECT val1, val2,val3 FROM table";
itemList = await _data.LoadData<itemList, dynamic>(sql, new { }, _config.GetConnectionString("default"));
}
void Change(object value) // Update num of rows
{
grid.Reload();
}
async void RowExpand(itemList item)
{
if (item.val4 == null)
{
string sql = "SELECT val1, val2, val3 FROM table2 WHERE val1 = @ForeignKey";
item.val4 = await _data.LoadData<secondItemList, dynamic>(sql, new { ForeignKey = item.val1}, _config.GetConnectionString("default"));
}
}
enchev
February 18, 2021, 9:56am
2
Without anything on how the grid is bound and configurated we will unable to help you. Check also the forum FAQ for reference.
hekra
February 18, 2021, 10:04am
3
Here we go:
<RadzenDropDown @bind-Value="pageSize" Data="@(new List<int>() { 10, 15, 50, 100 })" Style="margin-bottom: 20px" Change="@Change" />
<RadzenGrid @ref="grid" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterMode="FilterMode.Advanced" AllowPaging="true" PageSize=@pageSize
AllowSorting="true" Data="@itemList" TItem="itemList" AllowColumnResize="true" ColumnWidth="150px">
<Template Context="item">
<RadzenGrid AllowFiltering="true" AllowPaging="true" AllowSorting="true" Data="@item.val4" TItem="secondItemList">
<Columns>
<RadzenGridColumn TItem="secondItemList" Property="val1" Title="Value One" />
<RadzenGridColumn TItem="secondItemList" Property="val2" Title="Value Two" />
<RadzenGridColumn TItem="secondItemList" Property="val3" Title="Value Three" />
</Columns>
</RadzenGrid>
</Template>
<Columns>
<RadzenGridColumn TItem="itemList" Property="value1" Title="PSO Sort">
<FooterTemplate>
Total equips: <b>@itemList.Count()</b>
</FooterTemplate>
</RadzenGridColumn>
<RadzenGridColumn TItem="itemList" Property="val2" Title="Value Two" />
<RadzenGridColumn TItem="itemList" Property="val3" Title="Value Three" />
</Columns>
</RadzenGrid>
enchev
February 18, 2021, 10:06am
4
hekra:
Data="@item.val4"
It's not clear where RowExpand is attached that will populate your child data.
1 Like
hekra
February 18, 2021, 10:11am
5
Yes, that was indeed an issue! Now the data is loading, but with a side effect:
When I expand the data doesnt show. If I expand the next one, the data from the first one shows. If I expand the third one, the data from the second one shows...
enchev
February 18, 2021, 10:22am
6
I'm afraid that I cannot help in this case and you will need to debug your app to check what's going on. Check also the code created by Radzen Hiearchy/Master detail pages template with our OData Sample service for example:
hekra
February 18, 2021, 10:55am
7
I managed to fix it by adding:
await grid.Reload();
In RowExpand
Thanks for your help!
1 Like
hekra
February 19, 2021, 11:03am
8
Better fix: Change return type void to Task:
async void RowExpand(itemList item)
to
async Task RowExpand(itemList item)