How can I disable toolbar button ?

I have somethng like that

<SfGrid DataSource="@Orders" @ref="Grid">
    <GridTemplates>
        <ToolbarTemplate>
            <SfToolbar>
                <ToolbarEvents Clicked="ToolbarClickHandler"></ToolbarEvents>
                <ToolbarItems>
                    <ToolbarItem Type="@ItemType.Button" PrefixIcon="e-chevron-up icon" Id="collapseall" Text="Collapse All"></ToolbarItem>
                    <ToolbarItem Type="@ItemType.Button" PrefixIcon="e-chevron-down icon" Id="ExpandAll" Text="Expand All"></ToolbarItem>
                </ToolbarItems>
            </SfToolbar>
        </ToolbarTemplate>
    </GridTemplates>
</SfGrid>

Ho can i enable/disable buttons ?


4 Replies 1 reply marked as answer

TS Tomasz S. February 26, 2024 03:28 PM UTC

OK

I wasn't able to use

EnableToolbarItems

but I was able to disable it by reference. 


Is this the only and correct method?



MS Monisha Saravanan Syncfusion Team February 27, 2024 11:55 AM UTC


Hi Tomasz,


Greetings from Syncfusion.


We would like to inform you that EnableToolbarItems method will work only for inbuilt toolbar items. So we recommend you to use Disable property of toolbar item to dynamically disable or enable the toolbar item.


Sample: https://blazorplayground.syncfusion.com/embed/hNBTXhVwqseYgRyv?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5


<SfButton @onclick=@Disable>Enable/Disable</SfButton>

 

<SfGrid DataSource="@Orders" AllowPaging="true" Height="200" @ref="Grid" AllowGrouping="true">

    <GridTemplates>

        <ToolbarTemplate>

            <SfToolbar>

                <ToolbarEvents Clicked="ToolbarClickHandler"></ToolbarEvents>

                <ToolbarItems>

                    <ToolbarItem Disabled=@disable Type="@ItemType.Button" PrefixIcon="e-chevron-up icon" Id="collapseall" Text="Collapse All"></ToolbarItem>

                    <ToolbarItem Type="@ItemType.Button" PrefixIcon="e-chevron-down icon" Id="ExpandAll" Text="Expand All"></ToolbarItem>

                </ToolbarItems>

            </SfToolbar>

        </ToolbarTemplate>

    </GridTemplates>

    <GridGroupSettings Columns=@GroupOption></GridGroupSettings>

    <GridColumns>

    </GridColumns>

</SfGrid>

@code {

    public bool disable { get; set; } = false;

    private SfGrid<OrderData> Grid;

    public List<OrderData> Orders { get; set; }

    private string[] GroupOption = (new string[] { "OrderID" });

 

    public void Disable()

    {

        if(disable)

        {

            disable = !disable;

        }

        else

        {

            disable = true;

        }

    }

    public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)

    {

        if (args.Item.Text == "Collapse All")

        {

            this.Grid.CollapseAllGroupAsync();

        }

        if (args.Item.Text == "Expand All")

        {

            this.Grid.ExpandAllGroupAsync();

        }

    }

 



Please let us know if you have any concerns.


Regards,

Monisha


Marked as answer

TS Tomasz S. replied to Monisha Saravanan February 27, 2024 12:10 PM UTC

Thanks - its works.



MS Monisha Saravanan Syncfusion Team February 28, 2024 09:44 AM UTC

Hi Tomasz,


We are glad to hear that the reported issue has been resolved at your end. Kindly get back to us if you have further queries. As always we will be happy to assist you.


Regards,

Monisha


Loader.
Up arrow icon