Megabit / Blazorise

Blazorise is a component library built on top of Blazor with support for CSS frameworks like Bootstrap, Tailwind, Bulma, AntDesign, and Material.
https://blazorise.com/
Other
3.32k stars 535 forks source link

DataGrid: DataGridSelectEdit | Always refresh selectItems if Data count has changed #5868

Closed David-Moreira closed 4 days ago

David-Moreira commented 6 days ago

Testing Code :

@page "/"
@inject IVersionProvider VersionProvider
<DataGrid TItem="Employee"
Data="@employeeList"
@bind-SelectedRow="@selectedEmployee"
Responsive Filterable>
    <DataGridCommandColumn />
    <DataGridColumn Field="@nameof(Employee.FirstName)" Caption="First Name" Editable />
    <DataGridColumn Field="@nameof(Employee.LastName)" Caption="Last Name" Editable />
        <DataGridSelectColumn TItem="Employee" Field="@nameof( Employee.Category )" Caption="Category" Editable
        Data="employeeCategories" ValueField="(x) => ((EmployeeCategory)x).Id.ToString()" TextField="(x) => ((EmployeeCategory)x).Name" />

</DataGrid>

@code {
    private List<Employee> employeeList;
    public static List<EmployeeCategory> employeeCategories = new();
    private Employee selectedEmployee;
    protected override async Task OnInitializedAsync()
    {
        employeeCategories.Clear();

        employeeCategories.Add(new EmployeeCategory() { Name = "test1", Id = Guid.NewGuid() }); // is loaded into the dropdown
        await Task.Delay(1000);
        employeeCategories.Add(new EmployeeCategory() { Name = "test2", Id = Guid.NewGuid() }); // isn't loaded into the dropdown

        await base.OnInitializedAsync();
    }

    public class Employee
    {
        public Guid Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public int Salary { get; set; }
        public EmployeeCategory Category { get; set; }
    }

    public class EmployeeCategory
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
    }
}