Centering Buttons on a ToolBar.

1 Answer 41 Views
Toolbar
Gregory
Top achievements
Rank 1
Gregory asked on 09 Aug 2023, 03:33 PM
Is there way to simply center the items on a Tool bar in the middle of the toolbar. 

1 Answer, 1 is accepted

Sort by
0
Vasko
Telerik team
answered on 10 Aug 2023, 11:19 AM

Hello Gregory,

 

There is a way to center the items on a Toolbar built into the component - the Spacer Command Type. With it, you can align the toolbar items left or right of each other, or center them in the middle of the Toolbar, depending on what you want to achieve. Here's the sample code I used where I have 5 items on a Toolbar (which has the Spacer Command Type):  

@(Html.Kendo().ToolBar()
    .Name("ToolBar")
    .Items(items =>
    {
        items.Add().Type(CommandType.Spacer); // The Spacer here creates "space" for items declared after it

        items.Add().Type(CommandType.Button).Text("Button");
        items.Add().Type(CommandType.Button).Text("Toggle Button").Togglable(true);
        items.Add().Type(CommandType.ButtonGroup).Buttons(buttons =>
        {
            buttons.Add().Text("Bold").Togglable(true).Icon("bold");
            buttons.Add().Text("Italic").Togglable(true).Icon("italic");
            buttons.Add().Text("Underline").Togglable(true).Icon("underline");
        });

        items.Add().Type(CommandType.Spacer); // The Spacer here creates "space" for items declared before it
    })
)

I've also attached screenshots so you can see the results with and without using the Spacer and in addition, added some comments for clarification on what is happening. I hope this solution helps you out.

 

Kind regards,
Vasko
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Tags
Toolbar
Asked by
Gregory
Top achievements
Rank 1
Answers by
Vasko
Telerik team
Share this question
or