Skip to content

Commit d8305f0

Browse files
docs(grid): info for custom toolbar layout
1 parent d199443 commit d8305f0

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed
33.1 KB
Loading

components/grid/toolbar.md

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ position: 30
1010

1111
# Grid Toolbar
1212

13-
The grid provides a toolbar where you can add a variety of actions that are not tied to a concrete row:
13+
The grid provides a toolbar where you can add a variety of actions that are not tied to a concrete row.
14+
15+
To use a toolbar, define the `GridToolBar` tag of the grid. In it, you can use arbitrary HTML and components to get the desired layout, and also `GridCommandButton` instances in (you can read more about the features available in those buttons in the [Command Column]({%slug components/grid/columns/command%}) article).
16+
17+
>note The toolbar is not associated with an item from the data source. The `Item` field on the click event handler argument of a `GridCommandButton` will always be `null` and the `Edit`, `Update`, `Cancel` commands do not work with it.
18+
19+
In this article, you will learn how to use:
1420

1521
* [Built-in Commands](#built-in-commands)
1622
* [Custom Commands](#custom-commands)
23+
* [Custom Layout](#custom-layout)
1724

18-
To use a toolbar, define `GridCommandButton` instances in the `GridToolBar` tag of the grid. You can read more about the features available in those buttons in the [Command Column]({%slug components/grid/columns/command%}) article.
19-
20-
>note The toolbar is not associated with an item from the data source. The `Item` field on the click event handler argument will always be `null` and the `Edit`, `Update`, `Cancel` commands do not work with it.
2125

2226
## Built-in Commands
2327

@@ -140,6 +144,73 @@ You can use the toolbar to add buttons that invoke actions specific to your appl
140144
141145
![](images/custom-command-toolbar.png)
142146

147+
## Custom Layout
148+
149+
You can add your own HTML and components to create a more complex layout in the grid header to match your business needs. You can still use the grid command buttons, as well as other components and logic.
150+
151+
>caption Custom Grid Toolbar Layout
152+
153+
````CSHTML
154+
@result
155+
156+
<TelerikGrid Data=@MyData Pageable="true" PageSize="15" EditMode="@GridEditMode.Inline" Height="500px" OnCreate="@CreateHandler">
157+
<GridToolBar>
158+
<div style="background:yellow">
159+
<GridCommandButton Command="Add" Icon="add">Add Employee</GridCommandButton>
160+
</div>
161+
<div style="background: green;">
162+
<TelerikDropDownList Data="@( new List<string>() { "first", "second", "third" } )" TValue="string" TItem="string" ValueChanged="@( (string itm) => result = itm )"></TelerikDropDownList>
163+
</div>
164+
<div style="border: 1px solid red;">
165+
<div style="float:right;"><button @onclick="@( () => result = $"Custom button click on {DateTime.Now}" )">Click me</button></div>
166+
<div style="clear:both;"></div>
167+
</div>
168+
</GridToolBar>
169+
<GridColumns>
170+
<GridColumn Field=@nameof(SampleData.Name) Title="Employee Name" />
171+
<GridColumn Field=@nameof(SampleData.HireDate) Title="Hire Date" />
172+
<GridCommandColumn>
173+
<GridCommandButton Command="Edit" Icon="edit">Edit</GridCommandButton>
174+
<GridCommandButton Command="Save" Icon="save" ShowInEdit="true">Update</GridCommandButton>
175+
<GridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true">Cancel</GridCommandButton>
176+
</GridCommandColumn>
177+
</GridColumns>
178+
</TelerikGrid>
179+
180+
@code {
181+
string result;
182+
183+
private void CreateHandler(GridCommandEventArgs args)
184+
{
185+
SampleData newItem = args.Item as SampleData;
186+
MyData.Insert(0, newItem); // actual CRUD operations are not implemented, for brevity
187+
188+
result = string.Format("On {2} you added the employee {0} who was hired on {1}.", newItem.Name, newItem.HireDate, DateTime.Now);
189+
StateHasChanged();
190+
}
191+
192+
//in a real case, keep the models in dedicated locations, this is just an easy to copy and see example
193+
public class SampleData
194+
{
195+
public int ID { get; set; }
196+
public string Name { get; set; }
197+
public DateTime HireDate { get; set; }
198+
}
199+
200+
public List<SampleData> MyData = Enumerable.Range(1, 50).Select(
201+
x => new SampleData
202+
{
203+
ID = x,
204+
Name = "name " + x,
205+
HireDate = DateTime.Now.AddDays(-x)
206+
}).ToList();
207+
}
208+
````
209+
210+
>caption The result from the code snippet above, after adding a row, changing the dropdown and clicking the custom button.
211+
212+
![](images/custom-toolbar-layout.png)
213+
143214
## See Also
144215

145216
* [Live Demo: Grid Toolbar](https://demos.telerik.com/blazor-ui/grid/inlineediting)

0 commit comments

Comments
 (0)