Skip to content

Commit 8a967a8

Browse files
chore(Grid): address comments
1 parent c07744f commit 8a967a8

File tree

2 files changed

+222
-47
lines changed

2 files changed

+222
-47
lines changed

components/grid/toolbar.md

Lines changed: 89 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ position: 45
1010

1111
# Grid Toolbar
1212

13-
The [Blazor Grid](https://demos.telerik.com/blazor-ui/grid/overview) toolbar can render built-in and custom tools. This article describes the built-in tools and shows how to add custom tools or customize the toolbar.
13+
The [Blazor Grid](https://demos.telerik.com/blazor-ui/grid/overview) toolbar can render built-in and custom tools. This article describes the built-in tools and shows how to add [custom tools](#custom-tools) or create a [custom toolbar](#custom-toolbar-configuration).
1414

1515
## Built-in Tools
1616

17-
By default, the [Blazor Grid](https://demos.telerik.com/blazor-ui/grid/overview) displays all its built-in tools in the order below. Use the tool tag if you need to define a tool explicitly in a [custom toolbar configuration](#toolbar-configuration).
17+
By default, the [Blazor Grid](https://demos.telerik.com/blazor-ui/grid/overview) does not automatically render all built-in tools when a toolbar is added. To include specific tools in a [toolbar configuration](#toolbar-tools-configuration), you need to explicitly define them using the tool tags below.
1818

1919
### Command Tools
2020

@@ -29,8 +29,6 @@ By default, the [Blazor Grid](https://demos.telerik.com/blazor-ui/grid/overview)
2929

3030
### Layout Tools
3131

32-
@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout)
33-
3432
| Tool Name | Tool Tag | Description |
3533
| --- | --- | --- |
3634
| Spacer | `GridToolBarSpacerTool` | Consumes the available empty space and pushes the rest of the tools next to one another. |
@@ -39,52 +37,51 @@ By default, the [Blazor Grid](https://demos.telerik.com/blazor-ui/grid/overview)
3937

4038
In addition to built-in tools, the Grid also supports custom tools. Use the `<GridToolBarCustomTool>` tag, which is a standard Blazor `RenderFragment`. See the example below.
4139

42-
## Toolbar Configuration
40+
## Toolbar Tools Configuration
4341

44-
Add a `<GridToolBar>` tag inside `<TelerikGrid>` to configure a custom toolbar, for example:
42+
Add a `<GridToolBar>` tag inside `<TelerikGrid>` to configure a toolbar, for example:
4543

4644
* Arrange the Grid tools in a specific order;
4745
* Remove some of the built-in tools;
4846
* Add custom tools.
4947

50-
>caption Customize the Grid toolbar
48+
>important When configuring the Toolbar, you can use either the `<GridToolBar>` or the `<GridToolBarTemplate>`. Note that both cannot be used together.
49+
50+
>caption Grid Toolbar Tools
5151
5252
````RAZOR
5353
<TelerikGrid Data=@GridData
5454
EditMode="@GridEditMode.Inline"
5555
Pageable="true"
5656
OnUpdate=@UpdateItem
57-
OnDelete=@DeleteItem
5857
OnCreate=@CreateItem>
5958
<GridToolBar>
6059
<GridToolBarCustomTool>
6160
<TelerikButton OnClick="@OnToolbarCustomClick">Custom Grid Tool</TelerikButton>
6261
</GridToolBarCustomTool>
63-
62+
6463
<GridToolBarAddTool>
6564
Add a product
6665
</GridToolBarAddTool>
67-
66+
6867
<GridToolBarCsvExportTool>
6968
Export to CSV
7069
</GridToolBarCsvExportTool>
71-
70+
7271
<GridToolBarExcelExportTool>
7372
Export to Excel
7473
</GridToolBarExcelExportTool>
7574
7675
<GridToolBarSpacerTool />
76+
7777
<GridToolBarSearchBoxTool />
7878
</GridToolBar>
7979
<GridColumns>
8080
<GridColumn Field=@nameof(Person.EmployeeId) Editable="false" Visible="true" Width="200px" />
8181
<GridColumn Field=@nameof(Person.Name) Width="200px" />
8282
<GridColumn Field=@nameof(Person.AgeInYears) Title="Age" Visible="false" Width="240px" />
83-
<GridColumn Field=@nameof(Person.MeetingDate) Title="Meeting Date" Width="220px" />
8483
<GridColumn Field=@nameof(Person.HireDate) Title="Hire Date" Width="230px" />
85-
<GridColumn Field=@nameof(Person.GraduateGrade) Title="Graduate Grade" Width="200px" />
8684
<GridCommandColumn Width="200px">
87-
<GridCommandButton Command="Delete" Icon="@SvgIcon.Trash"></GridCommandButton>
8885
<GridCommandButton Command="Edit" Icon="@SvgIcon.Pencil"></GridCommandButton>
8986
<GridCommandButton Command="Save" Icon="@SvgIcon.Save" ShowInEdit="true"></GridCommandButton>
9087
</GridCommandColumn>
@@ -107,14 +104,12 @@ Add a `<GridToolBar>` tag inside `<TelerikGrid>` to configure a custom toolbar,
107104
for (int i = 0; i < 50; i++)
108105
{
109106
data.Add(new Person()
110-
{
111-
EmployeeId = i,
112-
Name = "Employee " + i.ToString(),
113-
HireDate = DateTime.Now.Date.AddDays(-(i * 2)),
114-
AgeInYears = 20,
115-
MeetingDate = DateTime.Now.Date.AddDays(i),
116-
GraduateGrade = (i % 5) + 2
117-
});
107+
{
108+
EmployeeId = i,
109+
Name = "Employee " + i.ToString(),
110+
HireDate = DateTime.Now.Date.AddDays(-(i * 2)),
111+
AgeInYears = 20
112+
});
118113
}
119114
GridData = new List<Person>(data);
120115
}
@@ -128,13 +123,6 @@ Add a `<GridToolBar>` tag inside `<TelerikGrid>` to configure a custom toolbar,
128123
GridData.Insert(0, argsItem);
129124
}
130125
131-
private void DeleteItem(GridCommandEventArgs args)
132-
{
133-
var argsItem = args.Item as Person;
134-
135-
GridData.Remove(argsItem);
136-
}
137-
138126
private void UpdateItem(GridCommandEventArgs args)
139127
{
140128
var argsItem = args.Item as Person;
@@ -143,9 +131,7 @@ Add a `<GridToolBar>` tag inside `<TelerikGrid>` to configure a custom toolbar,
143131
if (itemForEdit != null)
144132
{
145133
itemForEdit.AgeInYears = argsItem.AgeInYears;
146-
itemForEdit.GraduateGrade = argsItem.GraduateGrade;
147134
itemForEdit.HireDate = argsItem.HireDate;
148-
itemForEdit.MeetingDate = argsItem.MeetingDate;
149135
itemForEdit.Name = argsItem.Name;
150136
}
151137
}
@@ -158,26 +144,89 @@ Add a `<GridToolBar>` tag inside `<TelerikGrid>` to configure a custom toolbar,
158144
159145
public int? AgeInYears { get; set; }
160146
161-
public decimal? GraduateGrade { get; set; }
162-
163147
public DateTime HireDate { get; set; }
148+
}
149+
}
150+
````
164151

165-
public DateTime MeetingDate { get; set; }
152+
## Custom Toolbar Configuration
166153

167-
public Person()
168-
{
169-
GraduateGrade = 1;
170-
}
154+
Add a `<GridToolBarTemplate>` tag inside `<TelerikGrid>` to configure a custom toolbar. You can add your own HTML and components to create a more complex layout in the grid header to match your business needs and also `GridCommandButton` instances (read more about the features available in those buttons in the [Command Column](slug://components/grid/columns/command) article).
155+
156+
>caption Custom Grid Toolbar
157+
158+
````RAZOR
159+
@result
160+
161+
<TelerikGrid Data=@MyData Pageable="true" PageSize="15" EditMode="@GridEditMode.Inline" Height="500px" OnCreate="@CreateHandler">
162+
163+
<GridToolBarTemplate>
164+
<div style="display: block; flex-grow: 1;">
165+
@* the first level children in the toolbar get display: inline-flex and flex-shrink: 0 inherited from the grid,
166+
we change it here to show we can, or you can work with the layout the grid defines if it suits your needs *@
167+
168+
<div style="background:yellow">
169+
<GridCommandButton Command="Add" Icon="@SvgIcon.Plus">Add Employee</GridCommandButton>
170+
</div>
171+
<div style="background: green;">
172+
<TelerikDropDownList Data="@( new List<string>() { "first", "second", "third" } )" TValue="string" TItem="string" ValueChanged="@( (string itm) => result = itm )"></TelerikDropDownList>
173+
</div>
174+
175+
<div style="border: 1px solid red;">
176+
@* one example of aligning content to the right with flex *@
177+
<button style="display: flex; margin-left: auto;"
178+
@onclick="@( () => result = $"Custom button click on {DateTime.Now}" )">
179+
Click me
180+
</button>
181+
</div>
182+
</div>
183+
</GridToolBarTemplate>
184+
185+
<GridColumns>
186+
<GridColumn Field=@nameof(SampleData.Name) Title="Employee Name" />
187+
<GridColumn Field=@nameof(SampleData.HireDate) Title="Hire Date" />
188+
<GridCommandColumn>
189+
<GridCommandButton Command="Edit" Icon="@SvgIcon.Pencil">Edit</GridCommandButton>
190+
<GridCommandButton Command="Save" Icon="@SvgIcon.Save" ShowInEdit="true">Save</GridCommandButton>
191+
<GridCommandButton Command="Cancel" Icon="@SvgIcon.Cancel" ShowInEdit="true">Cancel</GridCommandButton>
192+
</GridCommandColumn>
193+
</GridColumns>
194+
</TelerikGrid>
195+
196+
@code {
197+
private string result;
198+
199+
private void CreateHandler(GridCommandEventArgs args)
200+
{
201+
SampleData newItem = args.Item as SampleData;
202+
MyData.Insert(0, newItem); // actual CRUD operations are not implemented, for brevity
203+
204+
result = string.Format("On {2} you added the employee {0} who was hired on {1}.", newItem.Name, newItem.HireDate, DateTime.Now);
205+
StateHasChanged();
171206
}
207+
208+
//in a real case, keep the models in dedicated locations, this is just an easy to copy and see example
209+
public class SampleData
210+
{
211+
public int ID { get; set; }
212+
public string Name { get; set; }
213+
public DateTime HireDate { get; set; }
214+
}
215+
216+
public List<SampleData> MyData = Enumerable.Range(1, 50).Select(
217+
x => new SampleData
218+
{
219+
ID = x,
220+
Name = "name " + x,
221+
HireDate = DateTime.Now.AddDays(-x)
222+
}).ToList();
172223
}
173224
````
174225

175-
176226
## Next Steps
177227

178228
* [Handle Grid events](slug://grid-events)
179229

180-
181230
## See Also
182231

183232
* [Grid Live Demo](https://demos.telerik.com/blazor-ui/grid/overview)

0 commit comments

Comments
 (0)