forked from syncfusion/ej2-aspnetmvc-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVirtualization.cshtml
204 lines (175 loc) · 7.32 KB
/
Virtualization.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Lists
@using Syncfusion.EJ2.DropDowns
@section ControlsSection{
@{ var template = "<div class='e-list-wrapper e-list-avatar'>" +
"<span id=\"${$imgUrl ? \'hideUI\' : \'showUI\' }\" class='e-avatar e-avatar-circle' icon='${icon}'> " +
"${icon}</span> <img id=\"${$imgUrl ? \'showUI\' : \'hideUI\' }\" class='e-avatar e-avatar-circle' src=\"${$imgUrl ? $imgUrl : \' \' }\" />" +
"<span class='e-list-content'>${name}</span></div>";
}
<div class="col-lg-8 control-section">
<!-- ListView element -->
@Html.EJS().ListView("ui-list").EnableVirtualization(true).CssClass("e-list-template").DataSource((IEnumerable<object>)ViewBag.listData).HeaderTitle("Contacts").ShowHeader(true).Height("500").Fields(new ListViewFieldSettings { Text = "name" }).Template(@template).ActionBegin("onActionBegin").ActionComplete("onActionComplete").Render()
</div>
<div class="col-lg-4 property-section">
<table id="property" title="Properties">
<tbody>
<tr>
<td style="width: 50%">
<div class="userselect">Load data</div>
</td>
<td style="width: 50%;padding-right: 10px">
<div>
@Html.EJS().DropDownList("ddl").Placeholder("Select a range").PopupHeight("200px").Index(0).DataSource(
(IEnumerable<object>)ViewBag.ddlData).Change("onChange").Fields(new DropDownListFieldSettings { Text = "text", Value = "value" }).Render()
</div>
</td>
</tr>
<tr>
<td style="width: 50%">
<div class="userselect">Time taken</div>
</td>
<td style="width: 50%;padding-right: 10px">
<div style="padding-left: 10px;padding-top: 0">
<span id="time">0 ms</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
}
@section Meta{
<meta name="description" content="This example demonstrates the Virtualization in ASP.NET MVC ListView control. Explore here for more details."/>
}
@section ActionDescription{
<div id="action-description">
<p>
This sample demonstrates the default functionalities of UI virtualization. Scroll list item to experience UI virtualization.
</p>
</div>
}
@section Description{
<div id="description">
<p>
UI virtualization is an optimization technique to avoid unnecessarily constructing and rendering objects for list items by loading only visible list items in a view port. This helps improve ListView performance when loading a large number of items. The
list items are updated dynamically while users scroll the list. The virtualization can be enabled by using the <code><a target='_blank' class='code' href='https://help.syncfusion.com/cr/cref_files/aspnetmvc-js2/Syncfusion.EJ2~Syncfusion.EJ2.Lists.ListView~EnableVirtualization.html'>EnableVirtualization</a></code> API in Listview.
</p>
</div>
}
<script type="text/javascript">
var listviewInstance;
var dataSource = {};
var startTime;
var endTime;
var liElement;
var commonData = [
{ name: 'Nancy', icon: 'N', id: '0', },
{ name: 'Andrew', icon: 'A', id: '1' },
{ name: 'Janet', icon: 'J', id: '2' },
{ name: 'Margaret', imgUrl: '@Url.Content("~/Content/images/listview/margaret.png")', id: '3' },
{ name: 'Steven', icon: 'S', id: '4' },
{ name: 'Laura', imgUrl: '@Url.Content("~/Content/images/listview/laura.png")', id: '5' },
{ name: 'Robert', icon: 'R', id: '6' },
{ name: 'Michael', icon: 'M', id: '7' },
{ name: 'Albert', imgUrl: '@Url.Content("~/Content/images/listview/albert.png")', id: '8' },
{ name: 'Nolan', icon: 'N', id: '9' }
];
[[1010, 'data1'], [5010, 'data5'], [10010, 'data10'], [25010, 'data25']].forEach(function (ds) {
var spyIndex;
var index;
var data = commonData.slice();
for (var i = 10; i <= ds[0]; i++) {
while (index === spyIndex) {
index = parseInt((Math.random() * 10).toString(), 10);
}
data.push({ name: data[index].name, icon: data[index].icon, imgUrl: data[index].imgUrl, id: i.toString() });
spyIndex = index;
}
dataSource[ds[1]] = data;
});
function onActionBegin() {
startTime = new Date();
listviewInstance = document.getElementById("ui-list").ej2_instances[0];
listviewInstance.dataSource = dataSource.data1;
}
function onActionComplete() {
endTime = new Date();
document.getElementById('time').innerText = (endTime.getTime() - startTime.getTime()) + ' ms';
liElement = document.getElementById('ui-list');
if (ej.base.Browser.isDevice) {
liElement.classList.add('ui-mobile');
}
ej.popups.createSpinner({
target: liElement
});
}
function onChange(e) {
ej.popups.showSpinner(liElement);
startTime = new Date();
listviewInstance.dataSource = dataSource['data' + e.value];
listviewInstance.dataBind();
endTime = new Date();
document.getElementById('time').innerText = (endTime.getTime() - startTime.getTime()) + ' ms';
ej.popups.hideSpinner(liElement);
}
</script>
<style>
/* ListView position alignment */
#ui-list.e-listview {
margin: auto;
max-width: 325px;
line-height: initial;
border: 1px solid lightgray;
}
/* ListView header alignment */
#ui-list.e-listview .e-list-header {
height: 50px
}
#ui-list.e-listview .e-list-header .e-text {
line-height: 18px
}
/* ListView template customization */
#ui-list.e-listview #showUI {
display: flex;
}
#ui-list.e-listview #hideUI {
display: none;
}
#ui-list.e-listview .e-list-item {
padding: 3px 0;
}
#ui-list.e-listview [icon="R"] {
background: lightgrey;
}
#ui-list.e-listview [icon="M"] {
background: pink;
}
#ui-list.e-listview [icon="A"] {
background: lightgreen;
}
#ui-list.e-listview [icon="S"] {
background: lightskyblue;
}
#ui-list.e-listview [icon="J"] {
background: orange;
}
#ui-list.e-listview [icon="N"] {
background: lightblue;
}
/* ListView theme customization */
.highcontrast #ui-list.e-listview .e-list-item,
.highcontrast #ui-list.e-listview .e-list-header {
background: rgb(0, 0, 0);
}
.highcontrast #ui-list.e-listview .e-list-item.e-active {
background: #ffd939;
color: #000000;
}
</style>
@section Title{
<title>ASP.NET MVC ListView Virtualization Example - Syncfusion Demos </title>
}
@section Header{
<h1 class='sb-sample-text'>Example of Virtualization in ASP.NET MVC ListView Control</h1>
}