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 pathvirtual-scrolling.tsx
More file actions
167 lines (153 loc) · 5.9 KB
/
virtual-scrolling.tsx
File metadata and controls
167 lines (153 loc) · 5.9 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { PivotViewComponent, IDataOptions, IDataSet, VirtualScroll, Inject } from '@syncfusion/ej2-react-pivotview';
import { SampleBase } from '../common/sample-base';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
/**
* PivotView Default Sample.
*/
const SAMPLE_CSS = `
.e-pivotview {
width: 100%;
height: 100%;
}
.image {
position: absolute;
background-repeat: no-repeat;
background-image: url('src/grid/images/spinner.gif');
background-position: center;
width: 16px;
height: 28px;
}
.e-bigger .image {
height: 36px;
}
#popup {
position: absolute;
background-color: transparent;
display: none;
z-index: 100;
}
#performanceTime {
float: right;
margin-top: 3px;
margin-right: 27px;
}
.e-bigger #performanceTime{
margin-top: 8px;
}`;
let dataSource: IDataOptions = {
data: [],
enableSorting: false,
expandAll: true,
formatSettings: [{ name: 'Price', format: 'C0' }],
rows: [{ name: 'ProductID' }],
columns: [{ name: 'Year' }],
values: [{ name: 'Price', caption: 'Unit Price' }, { name: 'Sold', caption: 'Unit Sold' }]
};
let customername: string[] = ['TOM', 'Hawk', 'Jon', 'Chandler', 'Monica', 'Rachel', 'Phoebe', 'Gunther',
'Ross', 'Geller', 'Joey', 'Bing', 'Tribbiani', 'Janice', 'Bong', 'Perk', 'Green', 'Ken', 'Adams'];
let city: string[] = ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Philadelphia', 'Phoenix', 'San Antonio', 'Austin',
'San Francisco', 'Columbus', 'Washington', 'Portland', 'Oklahoma', 'Las Vegas', 'Virginia', 'St. Louis', 'Birmingham'];
let applyBtn: ButtonComponent;
let pivotGridObj: PivotViewComponent;
let date1: number;
let date2: number;
let isInit: boolean;
function data(count: number) {
let result: Object[] = [];
let dt: number = 0;
for (let i: number = 1; i < (count + 1); i++) {
dt++;
let round: string;
let toString: string = i.toString();
if (toString.length === 1) {
round = '0000' + (i);
}
else if (toString.length === 2) {
round = '000' + i;
}
else if (toString.length === 3) {
round = '00' + i;
} else if (toString.length === 4) {
round = '0' + i;
} else {
round = toString;
}
result.push({
ProductID: 'PRO-' + round,
City: city[Math.round(Math.random() * city.length)] || city[0],
Year: "FY " + (dt + 2013),
CustomerName: customername[Math.round(Math.random() * customername.length)] || customername[0],
Price: Math.round(Math.random() * 5000) + 5000,
Sold: Math.round(Math.random() * 80) + 10,
});
if (dt / 4 == 1) {
dt = 0;
}
}
return result;
};
function show(): void {
document.getElementById('popup').style.display = 'inline-block';
};
export class VirtualScrolling extends SampleBase<{}, {}> {
onClick(args: any): void {
show();
isInit = true;
pivotGridObj.dataSource.data = data(100000) as IDataSet[];
date1 = new Date().getTime();
}
onDataBound(): void {
if (date1 && isInit) {
date2 = new Date().getTime();
document.getElementById('performanceTime').innerHTML = 'Time Taken: ' + (date2 - date1) / 1000 + ' sec';
}
isInit = false;
applyBtn.disabled = true;
document.getElementById('popup').style.display = 'none';
}
render() {
return (
<div className='control-pane'>
<style>
{SAMPLE_CSS}
</style>
<div className='control-section' style={{ overflow: 'auto' }}>
<div id="btn-control" style={{ marginBottom: '5px' }}>
<ButtonComponent id='apply' className='e-info' ref={(scope) => { applyBtn = scope; }} onClick={this.onClick.bind(this)} isPrimary={true}>Load 100K Data</ButtonComponent>
<span id="popup">
<span id="gif" className="image"></span>
</span>
<span id="performanceTime">Time Taken: 0 sec</span>
</div>
<PivotViewComponent id='PivotView' ref={(pivotview) => { pivotGridObj = pivotview }} dataSource={dataSource} enableVirtualization={true} width={860} height={300}
gridSettings={{ columnWidth: 140 }} dataBound={this.onDataBound}>
<Inject services={[VirtualScroll]} />
</PivotViewComponent>
</div>
<div id="action-description">
<p>This sample demonstrates virtual scrolling option available vertically and horizontally to load large records with ease.</p>
</div>
<div id="description">
<p>The pivot grid widget provides an optimized way to render rows and columns inside the view-port alone without calculating the value of the entire pivot.
To enable virtual scrolling, set <code> enableVirtualization</code> property to true.
</p>
<p>
<strong>NOTE:</strong> The <code> height</code> and <code> width</code> properties must be defined when enabling virtual
scrolling option.
</p>
<br />
<p>
<strong>Injecting Module:</strong>
</p>
<p>
The pivotgrid widget features are segregated into individual modules. To use the virtual scrolling option, inject
<code> VirtualScroll</code> module using the
<code> services</code> tag.
</p>
</div>
</div>
)
}
}