I upgraded my Telerik UI for Blazor to 3.7.0 from 2.3. There were some changes for datagrids, and I change my code accordingly. All of my data grids are showing records except one of them.
The data I am trying to show in Telerik Data Grid is of type T1<T2>.
I have replicated my code in Telerik RELP for blazor which can be accessed here.
<TelerikGrid @ref="@GridRef"
Height="30em"
TItem="CheckboxPair<SourceModel>"
Sortable="true"
OnStateInit="@((GridStateEventArgs<CheckboxPair<SourceModel>> args) => OnStateInitHandler(args))"
ScrollMode="@GridScrollMode.Scrollable"
OnRowRender="@OnRowRenderHandler">
<GridColumns>
<GridColumn Title="Data" Field="@nameof(SourceModel.Title)" Sortable="true">
<Template>
@{
var item = (CheckboxPair<SourceModel>)context;
@item.Value.Title
}
</Template>
</GridColumn>
<GridColumn Width="15%" Title="@nameof(SourceModel.Type)" Field="@nameof(SourceModel.Type)" Sortable="true">
<Template>
@{
var item = (CheckboxPair<SourceModel>)context;
@item.Value.Type
}
</Template>
</GridColumn>
</GridColumns>
</TelerikGrid>
@code {
public class CheckboxPair<T>
{
public CheckboxPair(T source, bool isChecked = false)
{
Value = source;
IsChecked = isChecked;
}
public bool IsChecked { get; set; }
public T Value { get; set; }
public bool IsDisable { get; set; }
}
public class SourceModel
{
public string Id { get; set; }
public string Title { get; set; } = string.Empty;
public string Type { get; set; }
}
List<CheckboxPair<SourceModel>> FactorySourceData { get; set; } = new();
TelerikGrid<CheckboxPair<SourceModel>> GridRef { get; set; }
protected override void OnInitialized()
{
FilterSourceData();
}
void OnStateInitHandler(GridStateEventArgs<CheckboxPair<SourceModel>> args)
{
args.GridState.SortDescriptors.Add(new SortDescriptor { Member = "Title", SortDirection = ListSortDirection.Ascending });
}
void OnRowRenderHandler(GridRowRenderEventArgs args)
{
var item = args.Item as CheckboxPair<SourceModel>;
args.Class = item.IsChecked ? "dim" : args.Class;
}
protected void ReadItems(GridReadEventArgs args)
{
FilterSourceData();
args.Data = FactorySourceData;
}
void FilterSourceData()
{
// This function gets list of data from server and set to FactorySourceData
var data = new SourceModel();
data.Id = "65hghjg42342";
data.Title = "data 1";
data.Type = "Factory";
var data2 = new SourceModel();
data2.Id = "hkjhjaksd68";
data2.Title = "data 2";
data2.Type = "Factory";
var checkboxPair1 = new CheckboxPair<SourceModel>(data);
var checkboxPair2 = new CheckboxPair<SourceModel>(data2, true);
FactorySourceData = new List<CheckboxPair<SourceModel>> {checkboxPair1, checkboxPair2};
}
}
After compiling, eventhough there are no errors, the records are not shown. What could be the problem, and what might be the solution?