This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvirtualization.tsx
More file actions
149 lines (135 loc) · 7.48 KB
/
virtualization.tsx
File metadata and controls
149 lines (135 loc) · 7.48 KB
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
/**
* ListView Virtualization Sample
*/
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { ListViewComponent, ListView, Inject, Virtualization } from '@syncfusion/ej2-react-lists';
import { DropDownListComponent, ChangeEventArgs } from '@syncfusion/ej2-react-dropdowns';
import { createSpinner, hideSpinner, showSpinner } from '@syncfusion/ej2-popups';
import { Browser } from '@syncfusion/ej2-base';
import { PropertyPane } from '../common/property-pane';
import { SampleBase } from '../common/sample-base';
import './virtualization.css';
export class UiVirtualization extends SampleBase<{}, {}> {
public listviewInstance: ListView;
public commonData: { [key: string]: string | object }[] = [];
public dataSource: { [key: string]: { [key: string]: string | object }[] } = {};
public startTime: Date;
public endTime: Date;
public liElement: HTMLElement;
constructor() {
super();
this.commonData = [
{ name: 'Nancy', icon: 'N', id: '0', },
{ name: 'Andrew', icon: 'A', id: '1' },
{ name: 'Janet', icon: 'J', id: '2' },
{ name: 'Margaret', imgUrl: './src/listview/images/margaret.png', id: '3' },
{ name: 'Steven', icon: 'S', id: '4' },
{ name: 'Laura', imgUrl: './src/listview/images/laura.png', id: '5' },
{ name: 'Robert', icon: 'R', id: '6' },
{ name: 'Michael', icon: 'M', id: '7' },
{ name: 'Albert', imgUrl: './src/listview/images/albert.png', id: '8' },
{ name: 'Nolan', icon: 'N', id: '9' }
];
[[1010, 'data1'], [5010, 'data5'], [10010, 'data10'], [25010, 'data25']].forEach((ds: string[] | number[]) => {
let data: { [key: string]: string | object }[] = this.commonData.slice();
let index: number;
let spyIndex: number;
for (let i: number = 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;
}
this.dataSource[ds[1]] = data;
});
}
public template: string = '<div class="e-list-wrapper e-list-avatar">' +
'<span class="e-avatar e-avatar-circle ${icon} ${$imgUrl ? \'hideUI\' : \'showUI\' }">' +
'${icon}</span> <img class="e-avatar e-avatar-circle ${$imgUrl ? \'showUI\' : \'hideUI\' }" ' +
'src="${$imgUrl ? $imgUrl : \' \' }" />' +
'<span class="e-list-content">${name}</span></div>';
public ddlDatasource = [
{ value: '1', text: '1k' },
{ value: '5', text: '5k' },
{ value: '10', text: '10k' },
{ value: '25', text: '25k' }
];
public ddlFields: Object = { text: 'text', value: 'value' };
public fields: Object = { text: 'name' };
public onActionComplete() {
this.liElement = document.getElementById('ui-list');
if (Browser.isDevice) {
this.liElement.classList.add('ui-mobile');
}
createSpinner({
target: this.liElement
});
this.endTime = new Date();
document.getElementById('time').innerText = (this.endTime.getTime() - this.startTime.getTime()) + ' ms';
}
public onActionBegin() {
this.startTime = new Date();
}
public onChange(e: ChangeEventArgs) {
showSpinner(this.liElement);
this.startTime = new Date();
this.listviewInstance.dataSource = this.dataSource['data' + e.value];
this.listviewInstance.dataBind();
this.endTime = new Date();
document.getElementById('time').innerText = (this.endTime.getTime() - this.startTime.getTime()) + ' ms';
hideSpinner(this.liElement);
}
render() {
return (
<div className='control-pane'>
<div className='ui-control-section control-section'>
<div className='col-lg-8'>
<div className="content-wrapper" >
<ListViewComponent id='ui-list' dataSource={this.dataSource.data1} enableVirtualization={true} headerTitle="Contacts" fields={this.fields} cssClass="e-list-template"
height={500} template={this.template} actionComplete={this.onActionComplete.bind(this)} ref={(listview) => { this.listviewInstance = listview }} actionBegin={this.onActionBegin.bind(this)} showHeader={true} >
<Inject services={[Virtualization]} />
</ListViewComponent>
</div>
</div>
<div id="#slider_event" className='col-lg-4 property-section'>
<PropertyPane title='Properties'>
<table id="Properties" title="Tooltip" className='property-panel-table' style={{ width: '100%' }}>
<tbody>
<tr>
<td style={{ width: '50%' }}>
<div className="userselect">Load data</div>
</td>
<td style={{ width: '50%', paddingRight: '10px' }} >
<div>
<DropDownListComponent id='ddl' dataSource={this.ddlDatasource} fields={this.ddlFields} index={0} change={this.onChange.bind(this)} placeholder="Select a range"
popupHeight="200px" />
</div>
</td>
</tr>
<tr>
<td style={{ width: '50%' }}>
<div className="userselect">Time taken</div>
</td>
<td style={{ width: '50%', paddingRight: '10px' }}>
<div style={{ paddingLeft: '10px', paddingTop: '0px' }}>
<span id="time">0 ms</span>
</div>
</td>
</tr>
</tbody>
</table>
</PropertyPane>
</div>
</div>
<div id="action-description">
<p>This sample demonstrates the <code>ListView</code> component with the virtual scrolling feature. Scroll the list content to experience the list items dynamic rendering and load more data into listview using dropdownlist.</p>
</div>
<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 list view 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 <a href="https://ej2.syncfusion.com/react/documentation/list-view/api-listViewComponent.html#enablevirtualization">enablevirtualization</a> API in Listview.</p>
</div>
</div>
)
}
}