@syncfusion/ej2-lists 29.2.4 → 30.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ej2-lists.min.js +1 -1
- package/dist/ej2-lists.umd.min.js +1 -1
- package/dist/global/ej2-lists.min.js +1 -1
- package/dist/global/index.d.ts +1 -1
- package/dist/ts/common/index.d.ts +4 -0
- package/dist/ts/common/index.ts +4 -0
- package/dist/ts/common/list-base.d.ts +415 -0
- package/dist/ts/common/list-base.ts +1362 -0
- package/dist/ts/component.d.ts +4 -0
- package/dist/ts/component.ts +4 -0
- package/dist/ts/index.d.ts +6 -0
- package/dist/ts/index.ts +6 -0
- package/dist/ts/list-view/index.d.ts +6 -0
- package/dist/ts/list-view/index.ts +6 -0
- package/dist/ts/list-view/list-view-model.d.ts +324 -0
- package/dist/ts/list-view/list-view.d.ts +844 -0
- package/dist/ts/list-view/list-view.ts +2732 -0
- package/dist/ts/list-view/virtualization.d.ts +97 -0
- package/dist/ts/list-view/virtualization.ts +947 -0
- package/dist/ts/sortable/index.d.ts +5 -0
- package/dist/ts/sortable/index.ts +5 -0
- package/dist/ts/sortable/sortable-model.d.ts +80 -0
- package/dist/ts/sortable/sortable.d.ts +146 -0
- package/dist/ts/sortable/sortable.ts +483 -0
- package/package.json +10 -11
- package/styles/bds-lite.css +7 -0
- package/styles/bds.css +7 -0
- package/styles/bootstrap-dark-lite.css +7 -0
- package/styles/bootstrap-dark.css +7 -0
- package/styles/bootstrap-lite.css +7 -0
- package/styles/bootstrap.css +7 -0
- package/styles/bootstrap4-lite.css +7 -0
- package/styles/bootstrap4.css +7 -0
- package/styles/bootstrap5-dark-lite.css +7 -0
- package/styles/bootstrap5-dark.css +7 -0
- package/styles/bootstrap5-lite.css +7 -0
- package/styles/bootstrap5.3-lite.css +7 -4
- package/styles/bootstrap5.3.css +7 -4
- package/styles/bootstrap5.css +7 -0
- package/styles/fabric-dark-lite.css +7 -0
- package/styles/fabric-dark.css +7 -0
- package/styles/fabric-lite.css +7 -0
- package/styles/fabric.css +7 -0
- package/styles/fluent-dark-lite.css +7 -0
- package/styles/fluent-dark.css +7 -0
- package/styles/fluent-lite.css +7 -0
- package/styles/fluent.css +7 -0
- package/styles/fluent2-lite.css +7 -0
- package/styles/fluent2.css +7 -0
- package/styles/highcontrast-light-lite.css +7 -0
- package/styles/highcontrast-light.css +7 -0
- package/styles/highcontrast-lite.css +7 -0
- package/styles/highcontrast.css +7 -0
- package/styles/list-view/_layout.scss +8 -0
- package/styles/list-view/_theme.scss +1 -1
- package/styles/list-view/bds.css +7 -0
- package/styles/list-view/bootstrap-dark.css +7 -0
- package/styles/list-view/bootstrap.css +7 -0
- package/styles/list-view/bootstrap4.css +7 -0
- package/styles/list-view/bootstrap5-dark.css +7 -0
- package/styles/list-view/bootstrap5.3.css +7 -4
- package/styles/list-view/bootstrap5.css +7 -0
- package/styles/list-view/fabric-dark.css +7 -0
- package/styles/list-view/fabric.css +7 -0
- package/styles/list-view/fluent-dark.css +7 -0
- package/styles/list-view/fluent.css +7 -0
- package/styles/list-view/fluent2.css +7 -0
- package/styles/list-view/highcontrast-light.css +7 -0
- package/styles/list-view/highcontrast.css +7 -0
- package/styles/list-view/material-dark.css +7 -0
- package/styles/list-view/material.css +7 -0
- package/styles/list-view/material3-dark.css +7 -0
- package/styles/list-view/material3.css +7 -0
- package/styles/list-view/tailwind-dark.css +7 -0
- package/styles/list-view/tailwind.css +7 -0
- package/styles/list-view/tailwind3.css +7 -0
- package/styles/material-dark-lite.css +7 -0
- package/styles/material-dark.css +7 -0
- package/styles/material-lite.css +7 -0
- package/styles/material.css +7 -0
- package/styles/material3-dark-lite.css +7 -0
- package/styles/material3-dark.css +7 -0
- package/styles/material3-lite.css +7 -0
- package/styles/material3.css +7 -0
- package/styles/tailwind-dark-lite.css +7 -0
- package/styles/tailwind-dark.css +7 -0
- package/styles/tailwind-lite.css +7 -0
- package/styles/tailwind.css +7 -0
- package/styles/tailwind3-lite.css +7 -0
- package/styles/tailwind3.css +7 -0
|
@@ -0,0 +1,947 @@
|
|
|
1
|
+
import { ListView, ItemCreatedArgs, classNames, Fields, UISelectedItem, SelectEventArgs } from './list-view';
|
|
2
|
+
import { EventHandler, append, isNullOrUndefined, detach, compile, formatUnit, select } from '@syncfusion/ej2-base';
|
|
3
|
+
import { ListBase } from '../common/list-base';
|
|
4
|
+
import { DataManager } from '@syncfusion/ej2-data';
|
|
5
|
+
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
+
/**
|
|
8
|
+
* ElementContext
|
|
9
|
+
*/
|
|
10
|
+
export interface ElementContext extends HTMLElement {
|
|
11
|
+
context: { [key: string]: string | object };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const listElementCount: number = 1.5;
|
|
15
|
+
const windowElementCount: number = 3;
|
|
16
|
+
|
|
17
|
+
export class Virtualization {
|
|
18
|
+
constructor(instance: ListView) {
|
|
19
|
+
this.listViewInstance = instance;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private listViewInstance: any;
|
|
23
|
+
private templateData: DataSource;
|
|
24
|
+
private topElementHeight: number;
|
|
25
|
+
private bottomElementHeight: number;
|
|
26
|
+
public listItemHeight: number;
|
|
27
|
+
private domItemCount: number;
|
|
28
|
+
private expectedDomItemCount: number;
|
|
29
|
+
private scrollPosition: number;
|
|
30
|
+
private onVirtualScroll: EventListener;
|
|
31
|
+
private updateUl: EventListener;
|
|
32
|
+
private checkListWrapper: Node;
|
|
33
|
+
private iconCssWrapper: Node;
|
|
34
|
+
public uiFirstIndex: number;
|
|
35
|
+
private uiLastIndex: number;
|
|
36
|
+
private totalHeight: number;
|
|
37
|
+
private topElement: HTMLElement;
|
|
38
|
+
private bottomElement: HTMLElement;
|
|
39
|
+
private activeIndex: number;
|
|
40
|
+
private uiIndices: { [key: string]: number[] };
|
|
41
|
+
private listDiff: number;
|
|
42
|
+
private elementDifference: number = 0;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* For internal use only.
|
|
46
|
+
*
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
public isNgTemplate(): boolean {
|
|
51
|
+
return !isNullOrUndefined(this.listViewInstance.templateRef) && typeof this.listViewInstance.templateRef !== 'string';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Checks if the platform is a Vue and its template property is a function type.
|
|
56
|
+
*
|
|
57
|
+
* @returns {boolean} indicating the result of the check
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
private isVueFunctionTemplate(): boolean {
|
|
61
|
+
return this.listViewInstance.isVue && typeof this.listViewInstance.template === 'function';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* For internal use only.
|
|
66
|
+
*
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
public uiVirtualization(): void {
|
|
71
|
+
this.wireScrollEvent(false);
|
|
72
|
+
const curViewDS: { [key: string]: object; }[] = this.listViewInstance.curViewDS as { [key: string]: object; }[];
|
|
73
|
+
const isRendered: boolean = this.listViewInstance.isRendered;
|
|
74
|
+
const firstIndex: number = isRendered && !isNullOrUndefined(this.uiFirstIndex) && this.uiLastIndex <= Object.keys(curViewDS).length
|
|
75
|
+
? this.uiFirstIndex : 0;
|
|
76
|
+
const firstDs: { [key: string]: object }[] = curViewDS.slice(firstIndex, firstIndex + 1);
|
|
77
|
+
this.listViewInstance.ulElement = this.listViewInstance.curUL = ListBase.createList(
|
|
78
|
+
this.listViewInstance.createElement, firstDs as { [key: string]: object; }[],
|
|
79
|
+
this.listViewInstance.listBaseOption, null, this.listViewInstance);
|
|
80
|
+
this.listViewInstance.contentContainer = this.listViewInstance.createElement('div', { className: classNames.container });
|
|
81
|
+
this.listViewInstance.element.appendChild(this.listViewInstance.contentContainer);
|
|
82
|
+
this.listViewInstance.contentContainer.appendChild(this.listViewInstance.ulElement);
|
|
83
|
+
this.listItemHeight = this.listViewInstance.ulElement.firstElementChild.getBoundingClientRect().height;
|
|
84
|
+
this.expectedDomItemCount = this.ValidateItemCount(10000);
|
|
85
|
+
this.updateDOMItemCount();
|
|
86
|
+
const lastIndex: number = isRendered && !isNullOrUndefined(this.uiLastIndex) && this.listDiff !== 0
|
|
87
|
+
? this.uiLastIndex : this.domItemCount - 1;
|
|
88
|
+
this.uiFirstIndex = firstIndex;
|
|
89
|
+
this.uiLastIndex = lastIndex;
|
|
90
|
+
const otherDs: { [key: string]: object; }[] = curViewDS.slice(firstIndex + 1, lastIndex + 1);
|
|
91
|
+
const listItems: HTMLElement[] = ListBase.createListItemFromJson(
|
|
92
|
+
this.listViewInstance.createElement, otherDs as { [key: string]: object; }[],
|
|
93
|
+
this.listViewInstance.listBaseOption, null, null, this.listViewInstance);
|
|
94
|
+
append(listItems, this.listViewInstance.ulElement);
|
|
95
|
+
this.listViewInstance.liCollection = <HTMLElement[] & NodeListOf<HTMLLIElement>>
|
|
96
|
+
this.listViewInstance.curUL.querySelectorAll('li');
|
|
97
|
+
this.topElement = this.listViewInstance.createElement('div');
|
|
98
|
+
this.listViewInstance.ulElement.insertBefore(this.topElement, this.listViewInstance.ulElement.firstElementChild);
|
|
99
|
+
this.bottomElement = this.listViewInstance.createElement('div');
|
|
100
|
+
this.listViewInstance.ulElement.insertBefore(this.bottomElement, null);
|
|
101
|
+
this.totalHeight = (Object.keys(curViewDS).length * this.listItemHeight) - (this.domItemCount * this.listItemHeight);
|
|
102
|
+
this.topElement.style.height = isRendered ? this.topElementHeight + 'px' : '0px';
|
|
103
|
+
this.bottomElement.style.height = isRendered ? (this.totalHeight - this.topElementHeight) + 'px' : this.totalHeight + 'px';
|
|
104
|
+
this.topElementHeight = isRendered ? this.topElementHeight : 0;
|
|
105
|
+
this.bottomElementHeight = isRendered ? (this.totalHeight - this.topElementHeight) : this.totalHeight;
|
|
106
|
+
this.listDiff = isRendered && Object.keys(curViewDS).length !== this.domItemCount ? this.listDiff : 0;
|
|
107
|
+
if (isRendered) {
|
|
108
|
+
this.listViewInstance.element.scrollTop = this.listViewInstance.previousScrollTop;
|
|
109
|
+
}
|
|
110
|
+
this.uiIndicesInitialization();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private wireScrollEvent(destroy: boolean): void {
|
|
114
|
+
if (!destroy) {
|
|
115
|
+
if (this.listViewInstance.isWindow) {
|
|
116
|
+
this.onVirtualScroll = this.onVirtualUiScroll.bind(this);
|
|
117
|
+
window.addEventListener('scroll', this.onVirtualScroll);
|
|
118
|
+
} else {
|
|
119
|
+
EventHandler.add(this.listViewInstance.element, 'scroll', this.onVirtualUiScroll, this);
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
if (this.listViewInstance.isWindow === true) {
|
|
123
|
+
window.removeEventListener('scroll', this.onVirtualScroll);
|
|
124
|
+
window.removeEventListener('scroll', this.updateUl);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
EventHandler.remove(this.listViewInstance.element, 'scroll', this.onVirtualUiScroll);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private ValidateItemCount(dataSourceLength: number): number {
|
|
133
|
+
const height: number = parseFloat(formatUnit(this.listViewInstance.height));
|
|
134
|
+
let itemCount: number;
|
|
135
|
+
if (this.listViewInstance.isWindow) {
|
|
136
|
+
itemCount = Math.round((window.innerHeight / this.listItemHeight) * windowElementCount);
|
|
137
|
+
} else {
|
|
138
|
+
if (typeof this.listViewInstance.height === 'string' && this.listViewInstance.height.indexOf('%') !== -1) {
|
|
139
|
+
itemCount = Math.round(
|
|
140
|
+
(this.listViewInstance.element.getBoundingClientRect().height / this.listItemHeight) * listElementCount);
|
|
141
|
+
} else {
|
|
142
|
+
itemCount = Math.round((height / this.listItemHeight) * listElementCount);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (itemCount > dataSourceLength) {
|
|
146
|
+
itemCount = dataSourceLength;
|
|
147
|
+
}
|
|
148
|
+
return itemCount;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public updateDOMItemCount(): void {
|
|
152
|
+
this.domItemCount = this.ValidateItemCount(Object.keys(this.listViewInstance.curViewDS).length);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private uiIndicesInitialization(): void {
|
|
156
|
+
this.uiIndices = { 'activeIndices': [], 'disabledItemIndices': [], 'hiddenItemIndices': [] };
|
|
157
|
+
const data: DataSource[] = this.listViewInstance.curViewDS as DataSource[];
|
|
158
|
+
for (let i: number = 0; i < data.length; i++) {
|
|
159
|
+
if (this.listViewInstance.showCheckBox && data[i as number][this.listViewInstance.fields.isChecked]) {
|
|
160
|
+
this.uiIndices.activeIndices.push(i);
|
|
161
|
+
}
|
|
162
|
+
if (!isNullOrUndefined((data[parseInt(i.toString(), 10)] as {[key: string]: object; })[this.listViewInstance.fields.enabled]) &&
|
|
163
|
+
!data[i as number][this.listViewInstance.fields.enabled]) {
|
|
164
|
+
(this.uiIndices.disabledItemIndices.push(i)) as number;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (this.isNgTemplate()) {
|
|
168
|
+
const items: ElementContext[] = this.listViewInstance.element.querySelectorAll('.' + classNames.listItem);
|
|
169
|
+
for (let index: number = 0; index < items.length; index++) {
|
|
170
|
+
items[index as number].context = this.listViewInstance.viewContainerRef.get(index).context;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public refreshItemHeight(): void {
|
|
176
|
+
if (this.listViewInstance.curViewDS.length) {
|
|
177
|
+
const curViewDS: { [key: string]: object; }[] = this.listViewInstance.curViewDS as { [key: string]: object; }[];
|
|
178
|
+
this.listItemHeight = (this.topElement.nextSibling as HTMLElement).getBoundingClientRect().height;
|
|
179
|
+
this.totalHeight = (Object.keys(curViewDS).length * this.listItemHeight) - (this.domItemCount * this.listItemHeight);
|
|
180
|
+
this.bottomElementHeight = this.totalHeight;
|
|
181
|
+
this.bottomElement.style.height = this.totalHeight + 'px';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private getscrollerHeight(startingHeight: number): number {
|
|
186
|
+
return this.listViewInstance.isWindow ? (((pageYOffset - startingHeight) <= 0) ? 0 :
|
|
187
|
+
(pageYOffset - startingHeight)) : ((this.listViewInstance.element.scrollTop - startingHeight) <= 0) ? 0 :
|
|
188
|
+
(this.listViewInstance.element.scrollTop - startingHeight);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private onVirtualUiScroll(): void {
|
|
192
|
+
let startingHeight: number;
|
|
193
|
+
const curViewDS: { [key: string]: object; }[] = this.listViewInstance.curViewDS as { [key: string]: object; }[];
|
|
194
|
+
this.listItemHeight = select('.e-list-item', this.listViewInstance.element).getBoundingClientRect().height;
|
|
195
|
+
this.totalHeight = (Object.keys(curViewDS).length * this.listItemHeight) - (this.domItemCount * this.listItemHeight);
|
|
196
|
+
if (this.listViewInstance.isWindow) {
|
|
197
|
+
startingHeight = this.listViewInstance.ulElement.getBoundingClientRect().top -
|
|
198
|
+
document.documentElement.getBoundingClientRect().top;
|
|
199
|
+
} else {
|
|
200
|
+
startingHeight = this.listViewInstance.headerEle ? this.listViewInstance.headerEle.getBoundingClientRect().height : 0;
|
|
201
|
+
}
|
|
202
|
+
this.scrollPosition = isNullOrUndefined(this.scrollPosition) ? 0 : this.scrollPosition;
|
|
203
|
+
const scroll: number = this.getscrollerHeight(startingHeight);
|
|
204
|
+
this.topElementHeight = this.listItemHeight * Math.floor(scroll / this.listItemHeight);
|
|
205
|
+
this.bottomElementHeight = this.totalHeight - this.topElementHeight;
|
|
206
|
+
[this.topElementHeight, this.bottomElementHeight] = scroll <= this.totalHeight ?
|
|
207
|
+
[this.topElementHeight, this.bottomElementHeight] : [this.totalHeight, 0];
|
|
208
|
+
if (this.topElementHeight !== parseFloat(this.topElement.style.height)) {
|
|
209
|
+
this.topElement.style.height = this.topElementHeight + 'px';
|
|
210
|
+
this.bottomElement.style.height = this.bottomElementHeight + 'px';
|
|
211
|
+
if (scroll > this.scrollPosition) {
|
|
212
|
+
const listDiff: number = Math.round(((this.topElementHeight / this.listItemHeight) - this.listDiff));
|
|
213
|
+
if (listDiff > (this.expectedDomItemCount + 5)) {
|
|
214
|
+
this.onLongScroll(listDiff, true);
|
|
215
|
+
} else {
|
|
216
|
+
this.onNormalScroll(listDiff, true);
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
const listDiff: number = Math.round((this.listDiff - (this.topElementHeight / this.listItemHeight)));
|
|
220
|
+
if (listDiff > (this.expectedDomItemCount + 5)) {
|
|
221
|
+
this.onLongScroll(listDiff, false);
|
|
222
|
+
} else {
|
|
223
|
+
this.onNormalScroll(listDiff, false);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
this.listDiff = Math.round(this.topElementHeight / this.listItemHeight);
|
|
228
|
+
if (typeof this.listViewInstance.onUIScrolled === 'function') {
|
|
229
|
+
this.listViewInstance.onUIScrolled();
|
|
230
|
+
}
|
|
231
|
+
this.scrollPosition = scroll;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private onLongScroll(listDiff: number, isScrollingDown: boolean): void {
|
|
235
|
+
let index: number = isScrollingDown ? (this.uiFirstIndex + listDiff) : (this.uiFirstIndex - listDiff);
|
|
236
|
+
const elements: HTMLElement[] = this.listViewInstance.ulElement.querySelectorAll('li');
|
|
237
|
+
for (let i: number = 0; i < elements.length; i++) {
|
|
238
|
+
this.updateUI(elements[i as number], index);
|
|
239
|
+
index++;
|
|
240
|
+
}
|
|
241
|
+
this.uiLastIndex = isScrollingDown ? (this.uiLastIndex + listDiff) : (this.uiLastIndex - listDiff);
|
|
242
|
+
this.uiFirstIndex = isScrollingDown ? (this.uiFirstIndex + listDiff) : (this.uiFirstIndex - listDiff);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private onNormalScroll(listDiff: number, isScrollingDown: boolean): void {
|
|
246
|
+
if (isScrollingDown) {
|
|
247
|
+
for (let i: number = 0; i < listDiff; i++) {
|
|
248
|
+
const index: number = ++this.uiLastIndex;
|
|
249
|
+
this.updateUI(this.topElement.nextElementSibling as HTMLElement, index, this.bottomElement);
|
|
250
|
+
this.uiFirstIndex++;
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
for (let i: number = 0; i < listDiff; i++) {
|
|
254
|
+
const index: number = --this.uiFirstIndex;
|
|
255
|
+
const target: HTMLElement = this.topElement.nextSibling as HTMLElement;
|
|
256
|
+
this.updateUI(this.bottomElement.previousElementSibling as HTMLElement, index, target);
|
|
257
|
+
this.uiLastIndex--;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private updateUiContent(element: HTMLElement, index: number): void {
|
|
263
|
+
const curViewDs: { [key: string]: Object; }[] = this.listViewInstance.curViewDS as DataSource[];
|
|
264
|
+
if (typeof (this.listViewInstance.dataSource as string[])[0] === 'string' ||
|
|
265
|
+
typeof (this.listViewInstance.dataSource as number[])[0] === 'number') {
|
|
266
|
+
element.dataset.uid = ListBase.generateId();
|
|
267
|
+
element.getElementsByClassName(classNames.listItemText)[0].innerHTML =
|
|
268
|
+
(this.listViewInstance.curViewDS as string[] | number[])[index as number].toString();
|
|
269
|
+
} else {
|
|
270
|
+
element.dataset.uid = (curViewDs[parseInt(index.toString(), 10)][this.listViewInstance.fields.id]) as string ?
|
|
271
|
+
(curViewDs[parseInt(index.toString(), 10)][this.listViewInstance.fields.id]) as string : (ListBase.generateId() as string);
|
|
272
|
+
element.getElementsByClassName(classNames.listItemText)[0].innerHTML =
|
|
273
|
+
(curViewDs[parseInt(index.toString(), 10)][this.listViewInstance.fields.text]) as string;
|
|
274
|
+
}
|
|
275
|
+
if (this.listViewInstance.showIcon) {
|
|
276
|
+
if (element.querySelector('.' + classNames.listIcon)) {
|
|
277
|
+
detach(element.querySelector('.' + classNames.listIcon));
|
|
278
|
+
}
|
|
279
|
+
if ((this.listViewInstance.curViewDS[index as number] as { [key: string]: object; })[this.listViewInstance.fields.iconCss]) {
|
|
280
|
+
const textContent: Element = element.querySelector('.' + classNames.textContent);
|
|
281
|
+
const curViewDS: { [key: string]: object; } =
|
|
282
|
+
this.listViewInstance.curViewDS[index as number] as { [key: string]: object; };
|
|
283
|
+
const iconCss: string = curViewDS[this.listViewInstance.fields.iconCss].toString();
|
|
284
|
+
const target: Element = this.listViewInstance.createElement('div', {
|
|
285
|
+
className: classNames.listIcon + ' ' + iconCss
|
|
286
|
+
});
|
|
287
|
+
textContent.insertBefore(target, element.querySelector('.' + classNames.listItemText));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (this.listViewInstance.showCheckBox && this.listViewInstance.fields.groupBy) {
|
|
291
|
+
if (!this.checkListWrapper) {
|
|
292
|
+
this.checkListWrapper = this.listViewInstance.curUL.querySelector('.' + classNames.checkboxWrapper).cloneNode(true);
|
|
293
|
+
}
|
|
294
|
+
const textContent: Element = element.querySelector('.' + classNames.textContent);
|
|
295
|
+
if ((this.listViewInstance.curViewDS[index as number] as { [key: string]: object; }).isHeader) {
|
|
296
|
+
if (element.querySelector('.' + classNames.checkboxWrapper)) {
|
|
297
|
+
element.classList.remove(classNames.checklist);
|
|
298
|
+
textContent.classList.remove(classNames.checkbox);
|
|
299
|
+
detach(element.querySelector('.' + classNames.checkboxWrapper));
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
if (!element.querySelector('.' + classNames.checkboxWrapper)) {
|
|
303
|
+
element.classList.add(classNames.checklist);
|
|
304
|
+
textContent.classList.add(classNames.checkbox);
|
|
305
|
+
if (this.listViewInstance.checkBoxPosition === 'Left') {
|
|
306
|
+
textContent.classList.add('e-checkbox-left');
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
textContent.classList.add('e-checkbox-right');
|
|
310
|
+
}
|
|
311
|
+
textContent.append(this.checkListWrapper.cloneNode(true));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
private changeElementAttributes(element: Element, index: number): void {
|
|
317
|
+
element.classList.remove(classNames.disable);
|
|
318
|
+
if (this.uiIndices.disabledItemIndices.length && this.uiIndices.disabledItemIndices.indexOf(index) !== -1) {
|
|
319
|
+
element.classList.add(classNames.disable);
|
|
320
|
+
}
|
|
321
|
+
(element as HTMLElement).style.display = '';
|
|
322
|
+
if (this.uiIndices.hiddenItemIndices.length && this.uiIndices.hiddenItemIndices.indexOf(index) !== -1) {
|
|
323
|
+
(element as HTMLElement).style.display = 'none';
|
|
324
|
+
}
|
|
325
|
+
if (this.listViewInstance.showCheckBox) {
|
|
326
|
+
const checklistElement: Element = element.querySelector('.' + classNames.checkboxWrapper);
|
|
327
|
+
element.classList.remove(classNames.selected);
|
|
328
|
+
element.classList.remove(classNames.focused);
|
|
329
|
+
if (checklistElement) {
|
|
330
|
+
checklistElement.removeAttribute('aria-checked');
|
|
331
|
+
checklistElement.firstElementChild.classList.remove(classNames.checked);
|
|
332
|
+
}
|
|
333
|
+
if (this.uiIndices.activeIndices.length && this.uiIndices.activeIndices.indexOf(index) !== -1 &&
|
|
334
|
+
!this.listViewInstance.curUL.querySelector(classNames.selected)) {
|
|
335
|
+
element.classList.add(classNames.selected);
|
|
336
|
+
checklistElement.firstElementChild.classList.add(classNames.checked);
|
|
337
|
+
checklistElement.setAttribute('aria-checked', 'true');
|
|
338
|
+
if (this.activeIndex === index) {
|
|
339
|
+
element.classList.add(classNames.focused);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
} else {
|
|
343
|
+
element.classList.remove(classNames.selected);
|
|
344
|
+
element.removeAttribute('aria-selected');
|
|
345
|
+
if (!isNullOrUndefined(this.activeIndex) && this.activeIndex === index &&
|
|
346
|
+
!this.listViewInstance.curUL.querySelector(classNames.selected)) {
|
|
347
|
+
element.classList.add(classNames.selected);
|
|
348
|
+
element.setAttribute('aria-selected', 'true');
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (this.listViewInstance.fields.groupBy) {
|
|
352
|
+
if ((this.listViewInstance.curViewDS as { [key: string]: object; }[])[index as number].isHeader) {
|
|
353
|
+
if (element.classList.contains(classNames.listItem)) {
|
|
354
|
+
element.classList.remove(classNames.listItem);
|
|
355
|
+
element.setAttribute('role', 'group');
|
|
356
|
+
element.classList.add(classNames.groupListItem);
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
if (element.classList.contains(classNames.groupListItem)) {
|
|
360
|
+
element.classList.remove(classNames.groupListItem);
|
|
361
|
+
element.setAttribute('role', 'listitem');
|
|
362
|
+
element.classList.add(classNames.listItem);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private findDSAndIndexFromId(
|
|
369
|
+
ds: DataSource[] | string[] | number[], fields: Fields | Element): DataSource {
|
|
370
|
+
const resultJSON: { [key: string]: object | number } = {};
|
|
371
|
+
fields = this.listViewInstance.getElementUID(fields);
|
|
372
|
+
if (!isNullOrUndefined(fields)) {
|
|
373
|
+
(ds as { [key: string]: object; }[]).some((data: { [key: string]: object; }, index: number) => {
|
|
374
|
+
if (((fields as { [key: string]: object; })[this.listViewInstance.fields.id] &&
|
|
375
|
+
(fields as { [key: string]: object; })[this.listViewInstance.fields.id]
|
|
376
|
+
=== (data[this.listViewInstance.fields.id] && data[this.listViewInstance.fields.id] as object) || fields === data)) {
|
|
377
|
+
resultJSON.index = index;
|
|
378
|
+
resultJSON.data = data;
|
|
379
|
+
return true;
|
|
380
|
+
} else {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return resultJSON as DataSource;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
public getSelectedItems(): UISelectedItem {
|
|
390
|
+
if (!isNullOrUndefined(this.activeIndex) || (this.listViewInstance.showCheckBox && this.uiIndices.activeIndices.length)) {
|
|
391
|
+
const dataCollection: string[] | { [key: string]: object; }[] = [];
|
|
392
|
+
const textCollection: string[] = [];
|
|
393
|
+
if (typeof (this.listViewInstance.dataSource as string[])[0] === 'string' ||
|
|
394
|
+
typeof (this.listViewInstance.dataSource as number[])[0] === 'number') {
|
|
395
|
+
const curViewDS: string[] | number[] = this.listViewInstance.curViewDS as string[] | number[];
|
|
396
|
+
if (this.listViewInstance.showCheckBox) {
|
|
397
|
+
const indices: number[] = this.uiIndices.activeIndices;
|
|
398
|
+
for (let i: number = 0; i < indices.length; i++) {
|
|
399
|
+
(dataCollection as string[]).push((curViewDS as string[])[indices[i as number]]);
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
text: dataCollection as string[],
|
|
403
|
+
data: dataCollection as string | number | string[] | number[] | {
|
|
404
|
+
[key: string]: object;
|
|
405
|
+
} | {
|
|
406
|
+
[key: string]: object;
|
|
407
|
+
}[],
|
|
408
|
+
index: this.uiIndices.activeIndices.map((index: number) =>
|
|
409
|
+
(this.listViewInstance.dataSource as string[]).indexOf((curViewDS as string[])[index as number]))
|
|
410
|
+
};
|
|
411
|
+
} else {
|
|
412
|
+
return {
|
|
413
|
+
text: curViewDS[this.activeIndex],
|
|
414
|
+
data: curViewDS[this.activeIndex],
|
|
415
|
+
index: (this.listViewInstance.dataSource as string[]).indexOf((curViewDS as string[])[this.activeIndex])
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
} else {
|
|
419
|
+
const curViewDS: { [key: string]: object | string }[] = this.listViewInstance.curViewDS as { [key: string]: object; }[];
|
|
420
|
+
const text: string = this.listViewInstance.fields.text;
|
|
421
|
+
if (this.listViewInstance.showCheckBox) {
|
|
422
|
+
const indexArray: number[] = this.uiIndices.activeIndices;
|
|
423
|
+
for (let i: number = 0; i < indexArray.length; i++) {
|
|
424
|
+
textCollection.push((curViewDS[indexArray[i as number]] as { [key: string]: string; })[`${text}`]);
|
|
425
|
+
(dataCollection as { [key: string]: Object; }[]).push(
|
|
426
|
+
curViewDS[indexArray[parseInt(i.toString(), 10)]] as DataSource);
|
|
427
|
+
}
|
|
428
|
+
const dataSource: { [key: string]: Object; }[] =
|
|
429
|
+
this.listViewInstance.dataSource instanceof DataManager
|
|
430
|
+
? curViewDS : this.listViewInstance.dataSource;
|
|
431
|
+
return {
|
|
432
|
+
text: textCollection,
|
|
433
|
+
data: dataCollection as string | number | number[] | string[] | { [key: string]: object; } |
|
|
434
|
+
{ [key: string]: object; }[],
|
|
435
|
+
index: this.uiIndices.activeIndices.map((index: number) =>
|
|
436
|
+
dataSource.indexOf(curViewDS[index as number] as DataSource))
|
|
437
|
+
};
|
|
438
|
+
} else {
|
|
439
|
+
const dataSource: { [key: string]: Object; }[] =
|
|
440
|
+
this.listViewInstance.dataSource instanceof DataManager
|
|
441
|
+
? curViewDS : this.listViewInstance.dataSource;
|
|
442
|
+
return {
|
|
443
|
+
text: curViewDS[this.activeIndex][this.listViewInstance.fields.text] as string,
|
|
444
|
+
data: curViewDS[this.activeIndex] as string | number | number[] | string[] | { [key: string]: object; } |
|
|
445
|
+
{ [key: string]: object; }[],
|
|
446
|
+
index: dataSource.indexOf(curViewDS[this.activeIndex])
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
} else {
|
|
451
|
+
return undefined;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
public selectItem(obj: Fields | HTMLElement | Element): void {
|
|
456
|
+
const resutJSON: { [key: string]: object | number } = this.findDSAndIndexFromId(this.listViewInstance.curViewDS, obj);
|
|
457
|
+
if (Object.keys(resutJSON).length) {
|
|
458
|
+
const isSelected: boolean = this.activeIndex === resutJSON.index;
|
|
459
|
+
let isChecked: boolean;
|
|
460
|
+
this.activeIndex = resutJSON.index as number;
|
|
461
|
+
if (this.listViewInstance.showCheckBox) {
|
|
462
|
+
if (this.uiIndices.activeIndices.indexOf(resutJSON.index as number) === -1) {
|
|
463
|
+
isChecked = true;
|
|
464
|
+
this.uiIndices.activeIndices.push(resutJSON.index as number);
|
|
465
|
+
} else {
|
|
466
|
+
isChecked = false;
|
|
467
|
+
this.uiIndices.activeIndices.splice(this.uiIndices.activeIndices.indexOf(resutJSON.index as number), 1);
|
|
468
|
+
}
|
|
469
|
+
if (this.listViewInstance.curUL.querySelector('.' + classNames.focused)) {
|
|
470
|
+
this.listViewInstance.curUL.querySelector('.' + classNames.focused).classList.remove(classNames.focused);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
if (this.listViewInstance.getLiFromObjOrElement(obj)) {
|
|
474
|
+
if (this.listViewInstance.showCheckBox) {
|
|
475
|
+
this.listViewInstance.setCheckboxLI(this.listViewInstance.getLiFromObjOrElement(obj));
|
|
476
|
+
} else {
|
|
477
|
+
this.listViewInstance.setSelectLI(this.listViewInstance.getLiFromObjOrElement(obj));
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
let eventArgs: { [key: string]: Object; };
|
|
481
|
+
if (typeof (this.listViewInstance.dataSource as string[])[0] === 'string' ||
|
|
482
|
+
typeof (this.listViewInstance.dataSource as number[])[0] === 'number') {
|
|
483
|
+
eventArgs = {
|
|
484
|
+
text: (this.listViewInstance.curViewDS as number[] | string[])[this.activeIndex],
|
|
485
|
+
data: (this.listViewInstance.curViewDS as number[] | string[])[this.activeIndex],
|
|
486
|
+
index: this.activeIndex
|
|
487
|
+
};
|
|
488
|
+
} else {
|
|
489
|
+
const curViewDS: { [key: string]: object; }[] = this.listViewInstance.curViewDS as { [key: string]: object; }[];
|
|
490
|
+
eventArgs = {
|
|
491
|
+
text: curViewDS[this.activeIndex][this.listViewInstance.fields.text],
|
|
492
|
+
data: curViewDS[this.activeIndex],
|
|
493
|
+
index: this.activeIndex
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
if (this.listViewInstance.showCheckBox) {
|
|
497
|
+
this.listViewInstance.trigger('select', eventArgs, (observedArgs: SelectEventArgs) => {
|
|
498
|
+
if (observedArgs.cancel) {
|
|
499
|
+
if (!isChecked) {
|
|
500
|
+
eventArgs.isChecked = isChecked;
|
|
501
|
+
this.uiIndices.activeIndices.push(resutJSON.index as number);
|
|
502
|
+
} else {
|
|
503
|
+
eventArgs.isChecked = !isChecked;
|
|
504
|
+
this.uiIndices.activeIndices.splice(this.uiIndices.activeIndices.indexOf(resutJSON.index as number), 1);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
} else if (!isSelected) {
|
|
509
|
+
this.listViewInstance.removeSelect();
|
|
510
|
+
this.listViewInstance.trigger('select', eventArgs, (observedArgs: SelectEventArgs) => {
|
|
511
|
+
if (observedArgs.cancel) {
|
|
512
|
+
this.activeIndex = undefined;
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
} else if (isNullOrUndefined(obj) && !this.listViewInstance.showCheckBox) {
|
|
518
|
+
this.listViewInstance.removeSelect();
|
|
519
|
+
this.activeIndex = undefined;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
public enableItem(obj: Fields | HTMLElement | Element): void {
|
|
524
|
+
const resutJSON: { [key: string]: object | number } = this.findDSAndIndexFromId(this.listViewInstance.curViewDS, obj);
|
|
525
|
+
if (Object.keys(resutJSON).length) {
|
|
526
|
+
this.uiIndices.disabledItemIndices.splice(this.uiIndices.disabledItemIndices.indexOf(resutJSON.index as number), 1);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
public disableItem(obj: Fields | HTMLElement | Element): void {
|
|
531
|
+
const resutJSON: { [key: string]: object | number } = this.findDSAndIndexFromId(this.listViewInstance.curViewDS, obj);
|
|
532
|
+
if (Object.keys(resutJSON).length && this.uiIndices.disabledItemIndices.indexOf(resutJSON.index as number) === -1) {
|
|
533
|
+
this.uiIndices.disabledItemIndices.push(resutJSON.index as number);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
public showItem(obj: Fields | HTMLElement | Element): void {
|
|
537
|
+
const resutJSON: { [key: string]: object | number } = this.findDSAndIndexFromId(this.listViewInstance.curViewDS, obj);
|
|
538
|
+
if (Object.keys(resutJSON).length) {
|
|
539
|
+
this.uiIndices.hiddenItemIndices.splice(this.uiIndices.hiddenItemIndices.indexOf(resutJSON.index as number), 1);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
public hideItem(obj: Fields | HTMLElement | Element): void {
|
|
544
|
+
const resutJSON: { [key: string]: object | number } = this.findDSAndIndexFromId(this.listViewInstance.curViewDS, obj);
|
|
545
|
+
if (Object.keys(resutJSON).length && this.uiIndices.hiddenItemIndices.indexOf(resutJSON.index as number) === -1) {
|
|
546
|
+
this.uiIndices.hiddenItemIndices.push(resutJSON.index as number);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
public removeItem(obj: HTMLElement | Element | Fields): void {
|
|
551
|
+
let dataSource: DataSource;
|
|
552
|
+
const curViewDS: DataSource[] = this.listViewInstance.curViewDS;
|
|
553
|
+
const resutJSON: { [key: string]: object | number } = this.findDSAndIndexFromId(curViewDS, obj);
|
|
554
|
+
if (Object.keys(resutJSON).length) {
|
|
555
|
+
dataSource = resutJSON.data as DataSource;
|
|
556
|
+
if (curViewDS[(resutJSON.index as number) - 1] &&
|
|
557
|
+
curViewDS[(resutJSON.index as number) - 1].isHeader &&
|
|
558
|
+
((curViewDS[(resutJSON.index as number) - 1])
|
|
559
|
+
.items as { [key: string]: object; }[]).length === 1) {
|
|
560
|
+
this.removeUiItem((resutJSON.index as number) - 1);
|
|
561
|
+
this.removeUiItem((resutJSON.index as number) - 1);
|
|
562
|
+
} else {
|
|
563
|
+
this.removeUiItem((resutJSON.index as number));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const listDataSource: DataSource[] = this.listViewInstance.dataSource instanceof DataManager
|
|
567
|
+
? this.listViewInstance.localData : this.listViewInstance.dataSource;
|
|
568
|
+
const index: number = listDataSource.indexOf(dataSource);
|
|
569
|
+
if (index !== -1) {
|
|
570
|
+
listDataSource.splice(index, 1);
|
|
571
|
+
this.listViewInstance.setViewDataSource(listDataSource);
|
|
572
|
+
}
|
|
573
|
+
// recollect all the list item into collection
|
|
574
|
+
|
|
575
|
+
this.listViewInstance.liCollection =
|
|
576
|
+
<HTMLElement[] & NodeListOf<HTMLLIElement>>this.listViewInstance.curUL.querySelectorAll('li');
|
|
577
|
+
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// eslint-disable-next-line
|
|
581
|
+
public setCheckboxLI(li: HTMLElement | Element, e?: MouseEvent | KeyboardEvent | FocusEvent): void {
|
|
582
|
+
const index: number = Array.prototype.indexOf.call(this.listViewInstance.curUL.querySelectorAll('li'), li) + this.uiFirstIndex;
|
|
583
|
+
this.activeIndex = Array.prototype.indexOf.call(this.listViewInstance.curUL.querySelectorAll('li'), li) + this.uiFirstIndex;
|
|
584
|
+
if (li.classList.contains(classNames.selected)) {
|
|
585
|
+
if (this.uiIndices.activeIndices.indexOf(index) === -1) {
|
|
586
|
+
this.uiIndices.activeIndices.push(index);
|
|
587
|
+
}
|
|
588
|
+
} else {
|
|
589
|
+
this.uiIndices.activeIndices.splice(this.uiIndices.activeIndices.indexOf(index), 1);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// eslint-disable-next-line
|
|
594
|
+
public setSelectLI(li: HTMLElement | Element, e?: MouseEvent | KeyboardEvent | FocusEvent): void {
|
|
595
|
+
this.activeIndex = Array.prototype.indexOf.call(this.listViewInstance.curUL.querySelectorAll('li'), li) + this.uiFirstIndex;
|
|
596
|
+
}
|
|
597
|
+
public checkedItem(checked: boolean): void {
|
|
598
|
+
if (checked) {
|
|
599
|
+
this.uiIndices.activeIndices = [];
|
|
600
|
+
this.activeIndex = undefined;
|
|
601
|
+
const data: DataSource[] = this.listViewInstance.curViewDS as DataSource[];
|
|
602
|
+
for (let index: number = 0; index < data.length; index++) {
|
|
603
|
+
if (!data[index as number].isHeader) {
|
|
604
|
+
this.uiIndices.activeIndices.push(index);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
} else {
|
|
609
|
+
this.activeIndex = undefined;
|
|
610
|
+
this.uiIndices.activeIndices = [];
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
private addUiItem(index: number): void {
|
|
616
|
+
// virtually new add list item based on the scollbar position
|
|
617
|
+
// if the scroll bar is at the top, just pretend the new item has been added since no UI
|
|
618
|
+
// change is required for the item that has been added at last but when scroll bar is at the bottom
|
|
619
|
+
// just detach top and inject into bottom to mimic new item is added
|
|
620
|
+
const curViewDs: DataSource[] = this.listViewInstance.curViewDS as DataSource[];
|
|
621
|
+
this.changeUiIndices(index, true);
|
|
622
|
+
if (this.activeIndex && this.activeIndex >= index) {
|
|
623
|
+
this.activeIndex++;
|
|
624
|
+
}
|
|
625
|
+
if (this.listViewInstance.showCheckBox &&
|
|
626
|
+
(curViewDs[index as number] as { [key: string]: object; })[this.listViewInstance.fields.isChecked]) {
|
|
627
|
+
this.uiIndices.activeIndices.push(index);
|
|
628
|
+
}
|
|
629
|
+
if (!parseFloat(this.bottomElement.style.height) && !parseFloat(this.topElement.style.height)) {
|
|
630
|
+
this.bottomElement.style.height = parseFloat(this.bottomElement.style.height) + this.listItemHeight + 'px';
|
|
631
|
+
}
|
|
632
|
+
if (parseFloat(this.bottomElement.style.height)) {
|
|
633
|
+
const liItem: HTMLElement = this.listViewInstance.curUL.lastElementChild.previousSibling as HTMLElement;
|
|
634
|
+
const target: HTMLElement = this.listViewInstance.getLiFromObjOrElement(curViewDs[index + 1]) ||
|
|
635
|
+
this.listViewInstance.getLiFromObjOrElement(curViewDs[index + 2]);
|
|
636
|
+
if (target) {
|
|
637
|
+
this.bottomElement.style.height = parseFloat(this.bottomElement.style.height) + this.listItemHeight + 'px';
|
|
638
|
+
this.updateUI(liItem, index, target);
|
|
639
|
+
}
|
|
640
|
+
} else {
|
|
641
|
+
const liItem: HTMLElement = this.listViewInstance.curUL.firstElementChild.nextSibling as HTMLElement;
|
|
642
|
+
let target: HTMLElement;
|
|
643
|
+
if ((Object.keys(this.listViewInstance.curViewDS).length - 1) === index) {
|
|
644
|
+
target = this.listViewInstance.curUL.lastElementChild as HTMLElement;
|
|
645
|
+
} else {
|
|
646
|
+
target = this.listViewInstance.getLiFromObjOrElement(curViewDs[index + 1]) ||
|
|
647
|
+
this.listViewInstance.getLiFromObjOrElement(curViewDs[index + 2]);
|
|
648
|
+
}
|
|
649
|
+
this.topElement.style.height = parseFloat(this.topElement.style.height) + this.listItemHeight + 'px';
|
|
650
|
+
this.uiFirstIndex++;
|
|
651
|
+
this.uiLastIndex++;
|
|
652
|
+
if (target) {
|
|
653
|
+
this.updateUI(liItem, index, target);
|
|
654
|
+
if (this.listViewInstance.isWindow === true) {
|
|
655
|
+
window.scrollTo(0, (pageYOffset + this.listItemHeight));
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
658
|
+
this.listViewInstance.element.scrollTop += this.listItemHeight;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
this.totalHeight += this.listItemHeight;
|
|
663
|
+
this.listDiff = Math.round(parseFloat(this.topElement.style.height) / this.listItemHeight);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
private removeUiItem(index: number): void {
|
|
667
|
+
this.totalHeight -= this.listItemHeight;
|
|
668
|
+
const curViewDS: DataSource = (this.listViewInstance.curViewDS as { [key: string]: object; }[])[index as number];
|
|
669
|
+
const liItem: HTMLElement = this.listViewInstance.getLiFromObjOrElement(curViewDS);
|
|
670
|
+
(this.listViewInstance.curViewDS as { [key: string]: object; }[]).splice(index, 1);
|
|
671
|
+
if (this.activeIndex && this.activeIndex >= index) {
|
|
672
|
+
this.activeIndex--;
|
|
673
|
+
}
|
|
674
|
+
if (liItem) {
|
|
675
|
+
if (this.domItemCount > Object.keys(this.listViewInstance.curViewDS).length) {
|
|
676
|
+
detach(liItem);
|
|
677
|
+
this.domItemCount--;
|
|
678
|
+
this.uiLastIndex--;
|
|
679
|
+
this.totalHeight = 0;
|
|
680
|
+
} else {
|
|
681
|
+
if (liItem.classList.contains(classNames.disable)) {
|
|
682
|
+
liItem.classList.remove(classNames.disable);
|
|
683
|
+
this.uiIndices.disabledItemIndices.splice(this.uiIndices.disabledItemIndices.indexOf(index), 1);
|
|
684
|
+
}
|
|
685
|
+
if (liItem.style.display === 'none') {
|
|
686
|
+
liItem.style.display = '';
|
|
687
|
+
this.uiIndices.hiddenItemIndices.splice(this.uiIndices.hiddenItemIndices.indexOf(index), 1);
|
|
688
|
+
}
|
|
689
|
+
if (this.listViewInstance.showCheckBox && liItem.classList.contains(classNames.selected)) {
|
|
690
|
+
this.listViewInstance.removeSelect();
|
|
691
|
+
this.uiIndices.activeIndices.splice(this.uiIndices.activeIndices.indexOf(index), 1);
|
|
692
|
+
const checklistElement: Element = liItem.querySelector('.' + classNames.checkboxWrapper);
|
|
693
|
+
checklistElement.removeAttribute('aria-checked');
|
|
694
|
+
checklistElement.firstElementChild.classList.remove(classNames.checked);
|
|
695
|
+
if (liItem.classList.contains(classNames.focused)) {
|
|
696
|
+
liItem.classList.remove(classNames.focused);
|
|
697
|
+
this.activeIndex = undefined;
|
|
698
|
+
}
|
|
699
|
+
} else if (liItem.classList.contains(classNames.selected)) {
|
|
700
|
+
this.listViewInstance.removeSelect();
|
|
701
|
+
this.activeIndex = undefined;
|
|
702
|
+
}
|
|
703
|
+
if (!parseFloat(this.bottomElement.style.height) && !parseFloat(this.topElement.style.height)) {
|
|
704
|
+
this.updateUI(liItem, this.uiLastIndex, this.bottomElement);
|
|
705
|
+
} else if (parseFloat(this.bottomElement.style.height)) {
|
|
706
|
+
this.bottomElement.style.height = parseFloat(this.bottomElement.style.height) - this.listItemHeight + 'px';
|
|
707
|
+
this.updateUI(liItem, this.uiLastIndex, this.bottomElement);
|
|
708
|
+
} else {
|
|
709
|
+
this.topElement.style.height = parseFloat(this.topElement.style.height) - this.listItemHeight + 'px';
|
|
710
|
+
this.updateUI(liItem, (this.uiFirstIndex - 1), this.topElement.nextSibling as HTMLElement);
|
|
711
|
+
this.uiLastIndex--;
|
|
712
|
+
this.uiFirstIndex--;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
this.changeUiIndices(index, false);
|
|
717
|
+
this.listDiff = Math.round(parseFloat(this.topElement.style.height) / this.listItemHeight);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
private changeUiIndices(index: number, increment: boolean): void {
|
|
721
|
+
const keys: string[] = Object.keys(this.uiIndices);
|
|
722
|
+
for (let ind: number = 0; ind < keys.length; ind++) {
|
|
723
|
+
this.uiIndices[keys[ind as number]] = this.uiIndices[keys[ind as number]].map((i: number) => {
|
|
724
|
+
if (i >= index) {
|
|
725
|
+
return increment ? ++i : --i;
|
|
726
|
+
} else {
|
|
727
|
+
return i;
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
public addItem(data: DataSource[], fields: Fields, dataSource: DataSource[], index: number): void {
|
|
734
|
+
for (let i: number = 0; i < data.length; i++) {
|
|
735
|
+
const currentItem: { [key: string]: object; } = data[i as number];
|
|
736
|
+
// push the given data to main data array
|
|
737
|
+
dataSource = this.listViewInstance.addItemAtIndex(index, dataSource, currentItem);
|
|
738
|
+
// recalculate all the group data or other datasource related things
|
|
739
|
+
this.listViewInstance.setViewDataSource(dataSource);
|
|
740
|
+
// render list items for first time due to no datasource present earlier
|
|
741
|
+
if (!this.domItemCount) {
|
|
742
|
+
// fresh rendering for first time
|
|
743
|
+
if ((this.listViewInstance.template || this.listViewInstance.groupTemplate) && !this.isNgTemplate()) {
|
|
744
|
+
this.listViewInstance.listBaseOption.template = null;
|
|
745
|
+
this.listViewInstance.listBaseOption.groupTemplate = null;
|
|
746
|
+
this.listViewInstance.listBaseOption.itemCreated = this.createUIItem.bind(this);
|
|
747
|
+
}
|
|
748
|
+
this.uiVirtualization();
|
|
749
|
+
// when expected expected DOM count doesn't meet the condition we need to create and inject new item into DOM
|
|
750
|
+
} else if (this.domItemCount < this.expectedDomItemCount) {
|
|
751
|
+
const ds: DataSource = this.listViewInstance.findItemFromDS(dataSource, fields);
|
|
752
|
+
|
|
753
|
+
if (ds instanceof Array) {
|
|
754
|
+
if (this.listViewInstance.ulElement) {
|
|
755
|
+
let index: number = (this.listViewInstance.curViewDS as DataSource[]).indexOf(currentItem);
|
|
756
|
+
// inject new list item into DOM
|
|
757
|
+
this.createAndInjectNewItem(currentItem, index);
|
|
758
|
+
|
|
759
|
+
// check for group header item
|
|
760
|
+
const curViewDS: DataSource =
|
|
761
|
+
(this.listViewInstance.curViewDS as DataSource[])[index - 1];
|
|
762
|
+
if (curViewDS && curViewDS.isHeader && (curViewDS.items as DataSource[]).length === 1) {
|
|
763
|
+
// target group item index in datasource
|
|
764
|
+
--index;
|
|
765
|
+
// inject new group header into DOM for previously created list item
|
|
766
|
+
this.createAndInjectNewItem(curViewDS, index);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
// recollect all the list item into collection
|
|
770
|
+
this.listViewInstance.liCollection =
|
|
771
|
+
<HTMLElement[] & NodeListOf<HTMLLIElement>>this.listViewInstance.curUL.querySelectorAll('li');
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
const index: number = (this.listViewInstance.curViewDS as { [key: string]: object; }[]).indexOf(currentItem);
|
|
775
|
+
// virtually new add list item based on the scollbar position
|
|
776
|
+
this.addUiItem(index);
|
|
777
|
+
// check for group header item needs to be added
|
|
778
|
+
const curViewDS: DataSource = (this.listViewInstance.curViewDS as DataSource[])[index - 1];
|
|
779
|
+
if (curViewDS && curViewDS.isHeader && (curViewDS.items as DataSource[]).length === 1) {
|
|
780
|
+
this.addUiItem(index - 1);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
private createAndInjectNewItem(itemData: DataSource, index: number): void {
|
|
787
|
+
// generate li item for given datasource
|
|
788
|
+
let target: HTMLElement;
|
|
789
|
+
const li: HTMLElement[] = ListBase.createListItemFromJson(
|
|
790
|
+
this.listViewInstance.createElement,
|
|
791
|
+
[itemData] as {[key: string]: object}[],
|
|
792
|
+
this.listViewInstance.listBaseOption,
|
|
793
|
+
null,
|
|
794
|
+
null,
|
|
795
|
+
this.listViewInstance);
|
|
796
|
+
// check for target element whether to insert before last item or group item
|
|
797
|
+
if ((Object.keys(this.listViewInstance.curViewDS).length - 1) === index) {
|
|
798
|
+
target = this.listViewInstance.curUL.lastElementChild as HTMLElement;
|
|
799
|
+
} else {
|
|
800
|
+
// target group header's first child item to append its header
|
|
801
|
+
target = this.listViewInstance.getLiFromObjOrElement(this.listViewInstance.curViewDS[index + 1]) ||
|
|
802
|
+
this.listViewInstance.getLiFromObjOrElement(this.listViewInstance.curViewDS[index + 2]);
|
|
803
|
+
}
|
|
804
|
+
if (this.listViewInstance.fields.groupBy
|
|
805
|
+
&& this.listViewInstance.curViewDS[index + 1]
|
|
806
|
+
&& this.listViewInstance.curViewDS[index + 1].isHeader) {
|
|
807
|
+
const targetEle: HTMLElement = this.listViewInstance.getLiFromObjOrElement(this.listViewInstance.curViewDS[index - 1]);
|
|
808
|
+
if (targetEle) {
|
|
809
|
+
target = targetEle.nextElementSibling as HTMLElement;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
// insert before the target element
|
|
813
|
+
this.listViewInstance.ulElement.insertBefore(li[0], target);
|
|
814
|
+
// increment internal DOM count, last index count for new element
|
|
815
|
+
this.domItemCount++;
|
|
816
|
+
if (this.bottomElementHeight <= 0) {
|
|
817
|
+
this.uiLastIndex++;
|
|
818
|
+
}
|
|
819
|
+
// recalculate the current item height, to avoid jumpy scroller
|
|
820
|
+
this.refreshItemHeight();
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
public createUIItem(args: ItemCreatedArgs): void {
|
|
824
|
+
if (!args.item.classList.contains('e-list-group-item')) {
|
|
825
|
+
this.templateData = args.curData.isHeader ? (args.curData as { [key: string]: object[]; }).items[0] as DataSource :
|
|
826
|
+
args.curData;
|
|
827
|
+
if (this.listViewInstance.showCheckBox) {
|
|
828
|
+
(this.listViewInstance as any).renderCheckbox(args);
|
|
829
|
+
if ((!isNullOrUndefined(this.listViewInstance.virtualCheckBox)) &&
|
|
830
|
+
(!isNullOrUndefined(this.listViewInstance.virtualCheckBox.outerHTML))) {
|
|
831
|
+
const div: HTMLElement = document.createElement('div');
|
|
832
|
+
const commonTemplate: string = '<div class="e-text-content" role="presentation"> ' +
|
|
833
|
+
'<span class="e-list-text"> ${' + this.listViewInstance.fields.text + '} </span></div>';
|
|
834
|
+
const templateFunction: Function = compile(this.listViewInstance.template || commonTemplate, this.listViewInstance);
|
|
835
|
+
const nodes: NodeList = templateFunction(this.templateData, this.listViewInstance);
|
|
836
|
+
if (this.listViewInstance.template && this.listViewInstance.isReact) {
|
|
837
|
+
this.listViewInstance.renderReactTemplates();
|
|
838
|
+
}
|
|
839
|
+
[].slice.call(nodes).forEach((ele: HTMLElement): void => {
|
|
840
|
+
div.appendChild(ele);
|
|
841
|
+
});
|
|
842
|
+
if (div.children && div.children[0]) {
|
|
843
|
+
div.children[0].classList.add('e-checkbox');
|
|
844
|
+
if (this.listViewInstance.checkBoxPosition === 'Left') {
|
|
845
|
+
div.children[0].classList.add('e-checkbox-left');
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
div.children[0].classList.add('e-checkbox-right');
|
|
849
|
+
}
|
|
850
|
+
if (this.listViewInstance.checkBoxPosition === 'Left') {
|
|
851
|
+
div.children[0].insertBefore(
|
|
852
|
+
this.listViewInstance.virtualCheckBox,
|
|
853
|
+
(div.childNodes[0] as HTMLElement).children[0]
|
|
854
|
+
);
|
|
855
|
+
} else {
|
|
856
|
+
div.children[0].appendChild(this.listViewInstance.virtualCheckBox);
|
|
857
|
+
}
|
|
858
|
+
while (args.item.lastChild) {
|
|
859
|
+
args.item.removeChild(args.item.lastChild);
|
|
860
|
+
}
|
|
861
|
+
[].slice.call(div.children).forEach((ele: HTMLElement): void => {
|
|
862
|
+
args.item.appendChild(ele);
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
public reRenderUiVirtualization(): void {
|
|
871
|
+
this.wireScrollEvent(true);
|
|
872
|
+
if (this.listViewInstance.contentContainer) {
|
|
873
|
+
detach(this.listViewInstance.contentContainer);
|
|
874
|
+
}
|
|
875
|
+
this.listViewInstance.preRender();
|
|
876
|
+
// resetting the dom count to 0, to avoid edge case of dataSource suddenly becoming zero
|
|
877
|
+
// and then manually adding item using addItem API
|
|
878
|
+
this.domItemCount = 0;
|
|
879
|
+
this.listViewInstance.header();
|
|
880
|
+
this.listViewInstance.setLocalData();
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
private updateUI(element: HTMLElement, index: number, targetElement?: HTMLElement): void {
|
|
884
|
+
const onChange: Function = this.isNgTemplate() ? this.onNgChange : this.onChange;
|
|
885
|
+
if (this.listViewInstance.template || this.listViewInstance.groupTemplate) {
|
|
886
|
+
const curViewDS: DataSource = (this.listViewInstance.curViewDS as DataSource[])[index as number];
|
|
887
|
+
element.dataset.uid = (curViewDS[this.listViewInstance.fields.id]) as any ?
|
|
888
|
+
(curViewDS[this.listViewInstance.fields.id]) as any : ListBase.generateId() as any;
|
|
889
|
+
onChange(curViewDS, element, this);
|
|
890
|
+
} else {
|
|
891
|
+
this.updateUiContent(element, index);
|
|
892
|
+
}
|
|
893
|
+
this.changeElementAttributes(element, index);
|
|
894
|
+
if (targetElement) {
|
|
895
|
+
this.listViewInstance.ulElement.insertBefore(element, targetElement);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Handles the UI change in vue for the list view.
|
|
901
|
+
*
|
|
902
|
+
* @param {DataSource} newData - The new data source for the list view.
|
|
903
|
+
* @param {ElementContext} listElement - The HTML element context for the list view.
|
|
904
|
+
* @param {Virtualization} virtualThis - The virtualization context for the list view.
|
|
905
|
+
* @returns {void}
|
|
906
|
+
*/
|
|
907
|
+
private onChange(newData: DataSource, listElement: ElementContext, virtualThis: Virtualization): void {
|
|
908
|
+
const liItem: HTMLElement[] = ListBase.createListItemFromJson(virtualThis.listViewInstance.createElement,
|
|
909
|
+
[newData] as { [key: string]: Object; }[],
|
|
910
|
+
virtualThis.listViewInstance.listBaseOption,
|
|
911
|
+
null, null, virtualThis.listViewInstance);
|
|
912
|
+
if (virtualThis.listViewInstance.isReact) {
|
|
913
|
+
virtualThis.listViewInstance.renderReactTemplates();
|
|
914
|
+
}
|
|
915
|
+
while (listElement.lastChild) {
|
|
916
|
+
listElement.removeChild(listElement.lastChild);
|
|
917
|
+
}
|
|
918
|
+
[].slice.call(liItem[0].children).forEach((ele: HTMLElement): void => {
|
|
919
|
+
listElement.appendChild(ele);
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
private onNgChange(newData: DataSource, listElement: ElementContext, virtualThis: Virtualization): void {
|
|
924
|
+
// compile given target element with template for new data
|
|
925
|
+
const templateCompiler: Function = compile(virtualThis.listViewInstance.template);
|
|
926
|
+
const resultElement: NodeList = templateCompiler(newData);
|
|
927
|
+
while (listElement.lastChild) {
|
|
928
|
+
listElement.removeChild(listElement.lastChild);
|
|
929
|
+
}
|
|
930
|
+
listElement.appendChild(resultElement[0]);
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
public getModuleName(): string {
|
|
934
|
+
return 'virtualization';
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
public destroy(): void {
|
|
938
|
+
this.wireScrollEvent(true);
|
|
939
|
+
this.topElement = null;
|
|
940
|
+
this.bottomElement = null;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
interface DataSource {
|
|
945
|
+
[key: string]: object;
|
|
946
|
+
}
|
|
947
|
+
|