<div class="d-flex flex-wrap">
@for (int i = 0; i < Permissions.Count; i++)
{
var c = i;
var per = Permissions.ElementAt(i);
<div class="col-3">
<h4>@per.Key</h4>
<SfListView DataSource="@per.Value" ShowCheckBox="true" @ref="@_lists[c]">
<ListViewFieldSettings Id="Id" Text="Permission" IsChecked="IsChecked"></ListViewFieldSettings>
</SfListView>
</div>
}
</div>
@code
{
private readonly SfListView<PermissionViewModel>[] _lists = new SfListView<PermissionViewModel>[PermissionsMessage.Permissions.Count];
private async Task<List<string>> GetSelectedValues()
{
StateHasChanged();
var list = new List<string>();
foreach (var sfListView in _lists)
{
var selected = await sfListView.GetSelectedItems();
var x = sfListView.DataSource.Where(x => x.IsChecked).Select(x => x.Id);
foreach (var l in x)
{
Console.WriteLine(l);
}
Console.WriteLine(sfListView.DataSource.Count());
if (selected.Data != null)
{
list.AddRange(selected.Data.Select(x =>
{
Console.WriteLine(x.Id);
return x.Id;
}));
}
}
return list;
}
}
When the data is loaded from the backed where IsChecked is set
The user makes some some selections
sfListView.GetSelectedItems() method is called
Only the newly selected value is returned. The previous selections are not returned, even though the UI shows the value as checked.