Skip to content

Commit 89ef195

Browse files
committed
docs(Grid): update after review
1 parent 3988ea8 commit 89ef195

File tree

1 file changed

+48
-96
lines changed

1 file changed

+48
-96
lines changed

knowledge-base/grid-compact-grid-with-small-elements.md

Lines changed: 48 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Make Compact Grid Elements Smaller
3-
description: How to make all elements in a Compact Grid smaller.
3+
description: How to reduce the size of elements and icons in a Compact Grid.
44
type: how-to
55
page_title: How to Make Compact Grid Elements Smaller
66
slug: grid-compact-grid-with-small-elements
@@ -30,67 +30,57 @@ I am using the [Grid sizing feature]({%slug grid-sizing%}) and my Grid is a Comp
3030
## Solution
3131

3232
1. Set the [Grid `Class` parameter]({%slug grid-overview%}#grid-parameters) to a custom CSS class. This allows you to target specific Grid instances.
33-
1. Use the defined class to [override the theme styles]({%slug themes-override%}).
34-
1. Set the required CSS styles to the desired elements in the Grid.
33+
1. Use the defined class to [override the theme styles]({%slug themes-override%}) of the desired elements in the Grid.
3534

3635
>caption Change Blazor Grid Elements Styles
3736
3837
````CSHTML
39-
<div class="demo-grid-container">
38+
<div>
4039
<div class="demo-small-grid">
4140
<TelerikGrid Size="@ThemeConstants.Grid.Size.Small"
4241
Data="@GridData"
4342
Sortable="true"
44-
PageSize="10"
43+
PageSize="5"
4544
Pageable="true"
4645
Resizable="true"
47-
Height="410px"
4846
FilterMode="@GridFilterMode.FilterRow"
49-
EditMode="@GridEditMode.Inline"
50-
OnUpdate="@MyOnUpdateHandler"
5147
Class="small-grid">
5248
<GridToolBarTemplate>
5349
<span>Small Grid Size</span>
5450
<span class="k-toolbar-spacer"></span>
5551
<GridCommandButton Command="ExcelExport" Icon="@SvgIcon.FileExcel">Export to Excel</GridCommandButton>
5652
</GridToolBarTemplate>
5753
<GridColumns>
58-
<GridColumn Field="@nameof(Product.Name)" Title="Product Name" Width="120px" />
59-
<GridColumn Field="@nameof(Product.Price)" DisplayFormat="{0:C2}" Width="120px" />
60-
<GridColumn Field="@nameof(Product.Released)" DisplayFormat="{0:D}" Width="190px" />
61-
<GridColumn Field="@nameof(Product.Discontinued)" Width="100px" />
62-
<GridCommandColumn Width="80px">
63-
<GridCommandButton Command="Edit" Icon="@SvgIcon.Pencil">Edit</GridCommandButton>
64-
<GridCommandButton Command="Save" Icon="@SvgIcon.Save" ShowInEdit="true">Update</GridCommandButton>
65-
<GridCommandButton Command="Cancel" Icon="@SvgIcon.Cancel" ShowInEdit="true">Cancel</GridCommandButton>
54+
<GridColumn Field="@nameof(Product.Name)" Title="Product Name" />
55+
<GridColumn Field="@nameof(Product.Price)" DisplayFormat="{0:C2}" />
56+
<GridColumn Field="@nameof(Product.Released)" DisplayFormat="{0:D}" />
57+
<GridColumn Field="@nameof(Product.Discontinued)" />
58+
<GridCommandColumn>
59+
<GridCommandButton Command="MyOwnCommand" Icon="@SvgIcon.InfoCircle" ShowInEdit="false" OnClick="@MyCustomCommandOnClickHandler">My Command</GridCommandButton>
6660
</GridCommandColumn>
6761
</GridColumns>
6862
</TelerikGrid>
6963
</div>
64+
<p>@CustomCommandResult</p>
7065
<div class="demo-default-grid">
7166
<TelerikGrid Data="@GridData"
7267
Sortable="true"
73-
PageSize="10"
68+
PageSize="5"
7469
Pageable="true"
7570
Resizable="true"
76-
Height="410px"
77-
FilterMode="@GridFilterMode.FilterRow"
78-
EditMode="@GridEditMode.Inline"
79-
OnUpdate="@MyOnUpdateHandler">
71+
FilterMode="@GridFilterMode.FilterRow">
8072
<GridToolBarTemplate>
8173
<span>Default Grid Size</span>
8274
<span class="k-toolbar-spacer"></span>
8375
<GridCommandButton Command="ExcelExport" Icon="@SvgIcon.FileExcel">Export to Excel</GridCommandButton>
8476
</GridToolBarTemplate>
8577
<GridColumns>
86-
<GridColumn Field="@nameof(Product.Name)" Title="Product Name" Width="120px" />
87-
<GridColumn Field="@nameof(Product.Price)" DisplayFormat="{0:C2}" Width="120px" />
88-
<GridColumn Field="@nameof(Product.Released)" DisplayFormat="{0:D}" Width="190px" />
89-
<GridColumn Field="@nameof(Product.Discontinued)" Width="100px" />
90-
<GridCommandColumn Width="80px">
91-
<GridCommandButton Command="Edit" Icon="@SvgIcon.Pencil">Edit</GridCommandButton>
92-
<GridCommandButton Command="Save" Icon="@SvgIcon.Save" ShowInEdit="true">Update</GridCommandButton>
93-
<GridCommandButton Command="Cancel" Icon="@SvgIcon.Cancel" ShowInEdit="true">Cancel</GridCommandButton>
78+
<GridColumn Field="@nameof(Product.Name)" Title="Product Name" />
79+
<GridColumn Field="@nameof(Product.Price)" DisplayFormat="{0:C2}" />
80+
<GridColumn Field="@nameof(Product.Released)" DisplayFormat="{0:D}" />
81+
<GridColumn Field="@nameof(Product.Discontinued)" />
82+
<GridCommandColumn>
83+
<GridCommandButton Command="MyOwnCommand" Icon="@SvgIcon.InfoCircle" ShowInEdit="false" OnClick="@MyCustomCommandOnClickHandler">My Command</GridCommandButton>
9484
</GridCommandColumn>
9585
</GridColumns>
9686
</TelerikGrid>
@@ -102,44 +92,28 @@ I am using the [Grid sizing feature]({%slug grid-sizing%}) and my Grid is a Comp
10292
10393
<style>
10494
/* reduce the size of the icons */
105-
.small-grid .k-svg-icon
95+
.small-grid .k-button .k-svg-icon
10696
/* or you can target specific icons
107-
.small-grid .k-svg-i-filter */ {
108-
width: 10px !important;
109-
height: 10px !important;
97+
.small-grid .k-svg-i-filter */ {
98+
width: 10px;
99+
height: 10px;
110100
}
111101
112102
/* reduce the size of the button icons */
113-
.small-grid .k-button-icon {
114-
min-width: 0px !important;
115-
}
116-
117-
/* reduce the font size of the grid elements */
118-
.small-grid .k-table-sm,
119-
.small-grid .k-grid-pager,
120-
.small-grid .k-button-flat,
121-
.small-grid .k-toolbar-sm,
122-
.small-grid .k-button-solid-base {
123-
font-size: x-small !important;
103+
.small-grid .k-icon-button .k-button-icon {
104+
min-width: 0px;
124105
}
125106
126-
/* handle positioning of both grids */
127-
.demo-grid-container {
128-
display: flex;
129-
flex-direction: @(ScreenIsSmall ? "column" : "row");
130-
flex-wrap: nowrap;
131-
gap: 1.5em;
107+
/* reduce the font size of the compact grid */
108+
:root .small-grid {
109+
--kendo-font-size: 9px;
132110
}
133111
134-
.demo-small-grid,
135-
.demo-default-grid {
136-
display: contents;
112+
/* handle width of both grids */
113+
.demo-small-grid .k-grid,
114+
.demo-default-grid .k-grid {
115+
width: @(ScreenIsSmall ? "100%" : "49%");
137116
}
138-
139-
.demo-small-grid .k-grid,
140-
.demo-default-grid .k-grid {
141-
width: @(ScreenIsSmall ? "100%" : "49%");
142-
}
143117
</style>
144118
145119
@code {
@@ -153,58 +127,36 @@ I am using the [Grid sizing feature]({%slug grid-sizing%}) and my Grid is a Comp
153127
}
154128
}
155129
130+
private MarkupString CustomCommandResult;
131+
156132
private List<Product> GridData { get; set; }
157133
158-
private async Task MyOnUpdateHandler(GridCommandEventArgs args)
134+
private async Task MyCustomCommandOnClickHandler(GridCommandEventArgs args)
159135
{
160-
Product theUpdatedItem = (Product)args.Item;
161-
await MyService.Update(theUpdatedItem);
162-
await GetGridData();
163-
}
136+
CustomCommandResult = new MarkupString(CustomCommandResult + string.Format("<br />Custom command triggered for item {0}", ((Product)args.Item).Id));
164137
165-
private async Task GetGridData()
166-
{
167-
GridData = await MyService.Read();
138+
Console.WriteLine("The Custom command fired. Please wait for the long operation to finish");
168139
}
169140
170141
protected override async Task OnInitializedAsync()
171142
{
172-
await GetGridData();
173-
}
143+
GridData = new List<Product>();
174144
175-
public static class MyService
176-
{
177-
private static List<Product> _data { get; set; } = new List<Product>();
145+
var rnd = new Random();
178146
179-
public static async Task<List<Product>> Read()
147+
for (int i = 1; i <= 30; i++)
180148
{
181-
if (_data.Count < 1)
182-
{
183-
var rnd = new Random();
184-
for (int i = 1; i < 50; i++)
149+
GridData.Add(new Product
185150
{
186-
_data.Add(new Product()
187-
{
188-
Id = i,
189-
Name = "Product name " + i,
190-
Price = (decimal)(rnd.Next(1, 50) * 3.14),
191-
Released = DateTime.Now.AddDays(-rnd.Next(1, 365)).AddYears(-rnd.Next(1, 10)).Date,
192-
Discontinued = i % 5 == 0
193-
});
194-
}
195-
}
196-
197-
return await Task.FromResult(_data);
151+
Id = i,
152+
Name = "Product name " + i,
153+
Price = (decimal)(rnd.Next(1, 50) * 3.14),
154+
Released = DateTime.Now.AddDays(-rnd.Next(1, 365)).AddYears(-rnd.Next(1, 10)).Date,
155+
Discontinued = i % 5 == 0
156+
});
198157
}
199158
200-
public static async Task Update(Product itemToUpdate)
201-
{
202-
var index = _data.FindIndex(i => i.Id == itemToUpdate.Id);
203-
if (index != -1)
204-
{
205-
_data[index] = itemToUpdate;
206-
}
207-
}
159+
base.OnInitialized();
208160
}
209161
210162
public class Product

0 commit comments

Comments
 (0)