We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Add a "Select All" option for each custom group in column chooser control

Hi. I need to know how to include a "Select All" option for each custom group in column chooser control when using templates. I can create the option but i don't know how to make it work:


My actual code is something like that:


Thanks!

David


3 Replies

SP Sarveswaran Palani Syncfusion Team January 4, 2023 03:46 AM UTC

Hi David,


Greetings from Syncfusion support.

From your query, we suspect that you want to know how to include a "Select All" option for each custom group in column chooser control when using templates. We suggest you to customize your requirement using column chooser template to overcome the issue at your end. Kindly refer the attached UG Documentation for your reference.

Reference: https://blazor.syncfusion.com/documentation/datagrid/column-chooser#column-chooser-template

Regards,

Sarvesh



VO Volker March 1, 2024 11:33 AM UTC

Please provide a working example for

  1. add a "Select all" within each group (only elements of a specific group)
  2. add a "Select all" for all columns (on top, default)
  3. add a "Search" (default)


When customicing the column selector these elements disappear:

Image_1821_1709211123875


This is my code so far based on this documentation:
https://blazor.syncfusion.com/documentation/datagrid/how-to/group-column-chooser-items

Image_4745_1709292756571
...
Image_1257_1709292577107

Cheers,
Volker



VN Vignesh Natarajan Syncfusion Team March 13, 2024 09:13 AM UTC

Hi Volker,


Sorry for the delay in getting back to you.


We would like to inform you that it is not possible to display SelectAll checkbox for each groups inside the ColumnChooser dialog. Hence we have provided support to ColumnChooserTemplate where we customize the column chooser dialog as per our requirement with custom component. As an example we have rendered the ListBox component inside the Grid ColumnChooser dialog and handled the show and hide actions of column.


Refer to the below code example.


<SfGrid ID="Grid" @ref="Grid" AllowPaging="true" DataSource="@Orders" ShowColumnChooser="true" Toolbar="@ToolbarItems">

    <GridColumnChooserSettings>

        <Template>

            @{

                var ContextData = context as ColumnChooserTemplateContext;

                <Counter @key="ContextData.Columns.Count" ValueChanged="OnChange" ColumnContext="ContextData"></Counter>

            }

        </Template>

        <FooterTemplate>

             @{

                var ContextData = context as ColumnChooserFooterTemplateContext;

            }

            <SfButton @onclick="@(async () => await ContextData.CancelAsync())">Abort</SfButton>

        </FooterTemplate>

    </GridColumnChooserSettings>

    <GridColumns>

        . . . . . .. .

    </GridColumns>

</SfGrid>

 

 

public async void OnChange(List<string> VisibleCols, List<string> HiddenCols)

 {

     await Grid.ShowColumnsAsync(VisibleCols.ToArray(), "Field");

     await Grid.HideColumnsAsync(HiddenCols.ToArray(), "Field");

 }

 

[Counter.razor]

 

<div class="setMargin">

    <SfTextBox Placeholder="Search" Input="@OnInput"></SfTextBox>

</div>

<SfListBox @ref="ListBox" TValue="string[]" DataSource="@CloneData" TItem="DataModel">

    <ListBoxFieldSettings GroupBy="Type" Text="Text" Value="Id" />

    <ListBoxSelectionSettings ShowCheckbox="true" ShowSelectAll="true"></ListBoxSelectionSettings>

    <ListBoxEvents ValueChange="ValueChange" TValue="string[]" TItem="DataModel"></ListBoxEvents>

</SfListBox>

<style>

    .setMargin {

        margin-bottom: 10px;

    }

</style>

@code

{

. . . . . .. . . .

 

    async Task OnInput(InputEventArgs eventArgs)

    {

        CloneData = DataSource.FindAll(e => e.Text.ToLower().StartsWith(eventArgs.Value.ToLower()));

        await Task.Delay(100);

        await Preselect();

    }

 

    protected override async Task OnInitializedAsync()

    {

        CloneData = DataSource;

        await Task.Delay(100);

        await Preselect();

    }

 

    List<DataModel> DataSource = new List<DataModel>

    {

        new DataModel() { Text = "Order ID", Id = "OrderID", Type ="Order Details" },

        new DataModel() { Text = "Customer ID", Id ="CustomerID", Type ="Customer Details"},

        new DataModel() { Text = "Employee ID", Id = "EmployeeID" , Type ="Product Details"},

        new DataModel() { Text = "First Name", Id = "FirstName" , Type ="Customer Details"},

        new DataModel() { Text = "Order Date", Id = "OrderDate" , Type ="Order Details"},

        new DataModel() { Text = "Last Name", Id = "LastName" , Type ="Customer Details"},

        new DataModel() { Text = "Hire Date", Id = "HireDate", Type ="Product Details"},

        new DataModel() { Text = "Title", Id = "Title", Type ="Order Details"},

        new DataModel() { Text = "Freight", Id = "Freight", Type ="Order Details"},

    };

 

    public async Task Preselect()

    {

        var cols = ColumnContext.Columns.FindAll(x => x.Visible == true).ToList();

        var selectlist = new List<DataModel>();

        foreach (var column in cols)

        {

            selectlist.Add(DataSource.Where(x => x.Text == column.HeaderText).FirstOrDefault());

        }

        if (selectlist.Count > 0)

        {

            if (ListBox != null)

            {

                await ListBox.SelectItemsAsync(selectlist.AsEnumerable());

            }

        }

    }

 

    public async Task OnCreated(List<GridColumn> args)

    {

        await Preselect();

    }

 

    public async Task ValueChange(ListBoxChangeEventArgs<string[], DataModel> args)

    {

        List<string> VisibleColumn = new List<string>();

        List<string> HiddenColumn = new List<string>();

        var columnHeader = DataSource.Select(x => x.Id).ToList();

        foreach (var col in columnHeader)

        {

            if (((IList)(args.Value)).Contains(col))

            {

                VisibleColumn.Add(col);

            }

            else

            {

                HiddenColumn.Add(col);

            }

           

        }

        ValueChanged.Invoke(VisibleColumn, HiddenColumn);

 

    }


Note: Similar way, we request you to render your own custom component inside the column chooser dialog to perform the operations. It will not be possible for us to provide solution to show select all check box in all groups using built in methods. Hence we suggest you to achieve your requirement by rendering a custom component inside it.


Attached the playground sample for your reference.


Sample: https://blazorplayground.syncfusion.com/rtVzNAiqUVEUPZyO


Please get back to us if you have further queries.


Regards,

Vignesh Natarajan


Loader.
Up arrow icon