I am attempting to get both checkbox lists to select all on load.
I have had issues trying to follow the example which appears to use @bind-Value and OnChange but I was not able to get it to work (and from what I understand it should not work)
Open to suggestions on how best to achieve preloading checkboxes with all items selected.
I am going to attempt to just use @bind-value with the settings below.
I believe the callback always has to have the signature Onchaged(object obj,string name) or it never gets called is that correct?
View
@page "/Counter"
@using Microsoft.Extensions.Configuration
@using VibeDashboardsDAL;
@using System.Data;
@inject IConfiguration Configuration
<style>
.ui-multiselect-item{
font-size:12px;
font-weight:bold
}
</style>
<EditForm Model="@formname">
<div class="row">
<div class="col-md-2 ">
<div>Select Facilities</div>
<RadzenListBox TValue="object"
AllowFiltering="false"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
Change=@(args => OnChange(args, "FacilityList"))
Multiple="true"
Data=@Facilities
TextProperty="FacilityName" ValueProperty="FacilityID"
Placeholder="Select All"
Style="max-height:100px;overflow:scroll;width:160px" />
</div>
<div class="col-md-2">
<div>Select Departments</div>
<RadzenListBox TValue="object"
AllowFiltering="false"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
Change=@(args => OnChange(args, "DepartmentList"))
Multiple="true"
Placeholder="Select All"
Data=@Departments
TextProperty="DepartmentName" ValueProperty="DepartmentID"
Style="max-height:100px;overflow:scroll;width:160px;font-size:12pt" />
</div>
</div>
</EditForm>
<h4>Selected Facilities</h4>
@string.Join(";", (IEnumerable<int>)SelectedFacilites)
<h4>Selected Departments</h4>
@string.Join(";", (IEnumerable<string>)SelectedDepartments)
Code Behind
namespace VibeDashboardsCore.Components
{
public partial class Counter
{
public string formname = "formname";
public List<DepartmentItem> Departments = new List<DepartmentItem> { new DepartmentItem { DepartmentID = "30", DepartmentName = "Parts" }
, new DepartmentItem { DepartmentID = "40", DepartmentName = "Service" }
};
public List<FacilityItem> Facilities = new List<FacilityItem> { new FacilityItem { FacilityID = 1, FacilityName = "fac1" },
new FacilityItem { FacilityID = 2, FacilityName = "fac2" },
new FacilityItem { FacilityID = 3, FacilityName = "fac3" },
new FacilityItem { FacilityID = 4, FacilityName = "fac4" },
new FacilityItem { FacilityID = 5, FacilityName = "fac5" },
new FacilityItem { FacilityID = 6, FacilityName = "fac6" },
new FacilityItem { FacilityID = 120, FacilityName = "fac7" }
};
//would change from using to using @bind-Values if i could get it to work
private IEnumerable<int> SelectedFacilites = Enumerable.Empty<int>();
private IEnumerable<string> SelectedDepartments = Enumerable.Empty<string>();
//I assume this is how we are supposed to handle multiple listboxes on the same page.. including other dropdowns
//Ye old switchboard approach.
public void OnChange(object value, string name)
{
if (name == "FacilityList")
{
SelectedFacilites = (IEnumerable<int>)value;
}
if (name == "DepartmentList")
{
SelectedDepartments = (IEnumerable<string>)value;
}
}
}
}