Skip to content

Commit c874797

Browse files
committed
KB Article: Justified items in the ListView (#212)
* feat(kb): ListView justified items * chore(kb): improvements to the justified items in listview KB * chore(kb): improvements to the KB article * chore(kb): fix wording
1 parent c784f3e commit c874797

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
30.6 KB
Loading
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: ListView Justified Items
3+
description: How to justify the items of the ListView
4+
type: how-to
5+
page_title: ListView Justified Items
6+
slug: listview-kb-justified-items
7+
position:
8+
tags:
9+
ticketid: 1503103
10+
res_type: kb
11+
---
12+
13+
## Environment
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>ListView for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
24+
## Description
25+
I would like to justify the items of the ListView to the center of the content area.
26+
27+
## Solution
28+
29+
The ListView is not aware of the shape and geometric sizes of the items it has in the content area thus adjusting its layout should be done by the application and handled case by case depending on the business needs.
30+
31+
To justify the items of the ListView to the center of the content area you can use some CSS. In order to cascade the rules to a single instance of the ListView, you can use the `Class` parameter that the component exposes. It will add a custom CSS class to the topmost HTML element.
32+
33+
>caption The result from the code snippet below
34+
35+
![listview justified items](images/listview-justified-items.png)
36+
37+
````CSHTML
38+
@* Use the Class parameter and some CSS to justify the ListView items to the center of the content area. *@
39+
40+
<style>
41+
.my-listview .k-listview-content { /* justifies the items in the ListView */
42+
display: flex;
43+
flex-wrap: wrap;
44+
justify-content: center;
45+
}
46+
47+
.listview-item { /*those styles are to create the layout of the listview item.*/
48+
height: 100px;
49+
width: 100px;
50+
display: inline-block;
51+
margin: 10px;
52+
border: 1px solid black;
53+
border-radius: 10px;
54+
padding: 10px;
55+
}
56+
</style>
57+
58+
59+
<div class="row">
60+
<div class="col-6">
61+
<TelerikListView Data="@ListViewData"
62+
Pageable="true"
63+
PageSize="4"
64+
Class="my-listview">
65+
<HeaderTemplate>
66+
<h2>Employee List</h2>
67+
</HeaderTemplate>
68+
<Template>
69+
<div class="listview-item">
70+
<h5>@context.Name</h5>
71+
<div>@context.Team</div>
72+
</div>
73+
</Template>
74+
</TelerikListView>
75+
</div>
76+
<div class="col-6">
77+
<TelerikListView Data="@ListViewData"
78+
Pageable="true"
79+
PageSize="4">
80+
<HeaderTemplate>
81+
<h2>Employee List</h2>
82+
</HeaderTemplate>
83+
<Template>
84+
<div class="listview-item">
85+
<h5>@context.Name</h5>
86+
<div>@context.Team</div>
87+
</div>
88+
</Template>
89+
</TelerikListView>
90+
</div>
91+
</div>
92+
93+
94+
@code{
95+
List<SampleData> ListViewData { get; set; } = Enumerable.Range(1, 8).Select(x => new SampleData
96+
{
97+
Id = x,
98+
Name = $"Name {x}",
99+
Team = $"Team {x % 3}"
100+
}).ToList();
101+
102+
public class SampleData
103+
{
104+
public int Id { get; set; }
105+
public string Name { get; set; }
106+
public string Team { get; set; }
107+
}
108+
}
109+
````

0 commit comments

Comments
 (0)