You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's an example of what I'm trying to do, where providing specific markup for the MultiSelectTemplate doesn't work as expected. Basically, I'd like to have a list of items that, as they are checked, populates another list real time. Currently, the code I ended up using (diff from below) populates a bound selected list, & when the selections need to be saved, the selected list gets assigned to the data model. it'd be great if the code could have a master list, where checking & unchecking items populates the data model in real time. plus, it'd be nice to have the form have a view & edit mode, where the checkboxes can't be checked when in view mode.
@page "/"
<Card Shadow="Shadow.Large" Margin="Margin.Is5">
<CardBody Padding="Padding.Is5">
<Button Color="Color.Secondary" Clicked="OnChangeEditStateClicked">Change Edit State</Button>
<br/>
Edit State = @isEditState
<br /><br />
<DataGrid TItem="Foo"
Data="@allFoos"
PageSize="1000000"
FixedHeader="true"
Filterable="true"
Sortable="true"
Editable="@isEditState"
SelectionMode="DataGridSelectionMode.Multiple">
<DataGridColumns>
<DataGridMultiSelectColumn TItem="Foo" Editable="@isEditState">
<MultiSelectTemplate>
<Blazorise.Check TValue="bool" Disabled="@(!isEditState)" CheckedChanged="@((isChecked) => { OnCheckChanged(isChecked, context.Item); context.SelectedChanged.InvokeAsync(isChecked); })" />
</MultiSelectTemplate>
</DataGridMultiSelectColumn>
<DataGridColumn TItem="Foo" Field="@nameof(Foo.Acronym)" Caption="Acronym" />
<DataGridColumn TItem="Foo" Field="@nameof(Foo.Name)" Caption="Name" />
</DataGridColumns>
</DataGrid>
<br /><br />
My Foos
<br />
<ListView TItem="Foo"
Data="myFoos"
TextField="(item) => item.Name"
ValueField="(item) => item.Acronym"
Mode="ListGroupMode.Static"
MaxHeight="300px">
</ListView>
</CardBody>
</Card>
@code {
public class Foo
{
public Foo()
{
Acronym = "";
Name = "";
}
public string? Acronym { get; set; }
public string? Name { get; set; }
}
private List<Foo> allFoos = new List<Foo>
{
new Foo { Acronym = "a1", Name = "n1" },
new Foo { Acronym = "a2", Name = "n2" },
new Foo { Acronym = "a3", Name = "n3" },
new Foo { Acronym = "a4", Name = "n4" },
new Foo { Acronym = "a5", Name = "n5" },
new Foo { Acronym = "a6", Name = "n6" },
new Foo { Acronym = "a7", Name = "n7" },
new Foo { Acronym = "a8", Name = "n8" }
};
private List<Foo> myFoos = new List<Foo>();
private bool isEditState = false;
private void OnChangeEditStateClicked()
{
isEditState = !isEditState;
}
private void OnCheckChanged(bool isChecked, Foo foo)
{
if (isChecked)
{
myFoos.Add(foo);
}
else
{
myFoos.Remove(foo);
}
}
}
David-Moreira
changed the title
DataGridMultiSelectColumn | Using The MultiSelectTemplate still triggers selection changed internally
DataGridMultiSelectColumn | Using The MultiSelectTemplate with a disabled checkbox still triggers selection changed internally
Oct 19, 2023
Here's an example of what I'm trying to do, where providing specific markup for the MultiSelectTemplate doesn't work as expected. Basically, I'd like to have a list of items that, as they are checked, populates another list real time. Currently, the code I ended up using (diff from below) populates a bound selected list, & when the selections need to be saved, the selected list gets assigned to the data model. it'd be great if the code could have a master list, where checking & unchecking items populates the data model in real time. plus, it'd be nice to have the form have a view & edit mode, where the checkboxes can't be checked when in view mode.
Originally posted by @RealityMasque in #5062 (reply in thread)
The text was updated successfully, but these errors were encountered: