Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGridMultiSelectColumn | Using The MultiSelectTemplate with a disabled checkbox still triggers selection changed internally #5087

Open
David-Moreira opened this issue Oct 19, 2023 · 0 comments
Assignees
Labels
Area: DataGrid Type: Bug 🐞 Something isn't working
Milestone

Comments

@David-Moreira
Copy link
Contributor

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);    
        }
    }
}

Originally posted by @RealityMasque in #5062 (reply in thread)

@David-Moreira David-Moreira self-assigned this Oct 19, 2023
@David-Moreira David-Moreira added Type: Bug 🐞 Something isn't working Area: DataGrid labels Oct 19, 2023
@David-Moreira 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
@David-Moreira David-Moreira added this to the 1.3 support milestone Oct 19, 2023
@stsrki stsrki modified the milestones: 1.3 support, 1.4 support Mar 19, 2024
@stsrki stsrki added this to Support Aug 3, 2024
@stsrki stsrki moved this to 🔙 Backlog in Support Aug 3, 2024
@stsrki stsrki modified the milestones: 1.4 support, 1.6 support Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: DataGrid Type: Bug 🐞 Something isn't working
Projects
Status: 🔙 Backlog
Development

No branches or pull requests

2 participants