lightning-base-components 1.14.2-alpha → 1.14.3-alpha
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/metadata/raptor.json +1 -0
- package/package.json +17 -1
- package/scopedImports/@salesforce-label-LightningDualListbox.movedOptionsPlural.js +1 -0
- package/scopedImports/@salesforce-label-LightningDualListbox.movedOptionsSingular.js +1 -0
- package/scopedImports/@salesforce-label-LightningErrorMessage.validitySelectAtleastOne.js +1 -0
- package/scopedImports/@salesforce-label-LightningMap.titleWithAddress.js +1 -0
- package/src/lightning/ariaObserver/__docs__/ariaObserver.md +142 -0
- package/src/lightning/buttonMenu/keyboard.js +0 -10
- package/src/lightning/card/card.html +6 -0
- package/src/lightning/checkboxGroup/checkboxGroup.html +2 -2
- package/src/lightning/checkboxGroup/checkboxGroup.js +6 -1
- package/src/lightning/colorPickerCustom/colorPickerCustom.js +20 -1
- package/src/lightning/datatable/__docs__/datatable.md +55 -0
- package/src/lightning/datatable/__examples__/basic/basic.html +1 -1
- package/src/lightning/datatable/columns-shared.js +1 -1
- package/src/lightning/datatable/datatable.js +97 -24
- package/src/lightning/datatable/errors.js +20 -9
- package/src/lightning/datatable/headerActions.js +77 -49
- package/src/lightning/datatable/inlineEdit.js +505 -370
- package/src/lightning/datatable/inlineEditShared.js +24 -0
- package/src/lightning/datatable/keyboard.js +1 -1
- package/src/lightning/datatable/renderManager.js +241 -129
- package/src/lightning/datatable/rowLevelActions.js +17 -13
- package/src/lightning/datatable/rowNumber.js +54 -20
- package/src/lightning/datatable/rowSelection.js +760 -0
- package/src/lightning/datatable/rowSelectionShared.js +79 -0
- package/src/lightning/datatable/rows.js +16 -5
- package/src/lightning/datatable/state.js +10 -1
- package/src/lightning/datatable/templates/div/div.css +4 -0
- package/src/lightning/datatable/templates/div/div.html +1 -0
- package/src/lightning/datatable/utils.js +14 -0
- package/src/lightning/dualListbox/dualListbox.html +1 -1
- package/src/lightning/dualListbox/dualListbox.js +42 -0
- package/src/lightning/inputUtils/validity.js +12 -1
- package/src/lightning/pillContainer/__docs__/pillContainer.md +45 -1
- package/src/lightning/positionLibrary/positionLibrary.js +31 -43
- package/src/lightning/primitiveCellActions/primitiveCellActions.js +69 -12
- package/src/lightning/primitiveCellFactory/cellWithStandardLayout.html +13 -11
- package/src/lightning/primitiveCellFactory/primitiveCellFactory.js +13 -8
- package/src/lightning/primitiveDatatableIeditPanel/primitiveDatatableIeditPanel.html +17 -14
- package/src/lightning/primitiveDatatableIeditPanel/primitiveDatatableIeditPanel.js +167 -98
- package/src/lightning/primitiveDatatableIeditTypeFactory/primitiveDatatableIeditTypeFactory.js +94 -69
- package/src/lightning/primitiveDatatableStatusBar/primitiveDatatableStatusBar.html +4 -4
- package/src/lightning/primitiveDatatableStatusBar/primitiveDatatableStatusBar.js +4 -4
- package/src/lightning/primitiveHeaderActions/primitiveHeaderActions.js +99 -37
- package/src/lightning/progressIndicator/progressIndicator.js +1 -1
- package/src/lightning/progressStep/progressStep.js +1 -1
- package/src/lightning/staticMap/staticMap.html +1 -0
- package/src/lightning/staticMap/staticMap.js +39 -2
- package/src/lightning/utils/classSet.js +4 -1
- package/src/lightning/datatable/inlineEdit-shared.js +0 -14
- package/src/lightning/datatable/selector-shared.js +0 -38
- package/src/lightning/datatable/selector.js +0 -527
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the dirty/unsaved value of a cell that resulted from an inline
|
|
3
|
+
* edit change. If no change was made on the cell, this function
|
|
4
|
+
* returns `undefined`.
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} state - datatable's state object
|
|
7
|
+
* @param {String} rowKeyValue - computed id for the row
|
|
8
|
+
* @param {String} colKeyValue - computed id for the column
|
|
9
|
+
* @returns {String} The dirty/unsaved value of the cell.
|
|
10
|
+
* If no change was made, this returns `undefined`
|
|
11
|
+
*/
|
|
12
|
+
export function getDirtyValueFromCell(state, rowKeyValue, colKeyValue) {
|
|
13
|
+
const dirtyValues = state.inlineEdit.dirtyValues;
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
dirtyValues &&
|
|
17
|
+
dirtyValues[rowKeyValue] &&
|
|
18
|
+
dirtyValues[rowKeyValue][colKeyValue]
|
|
19
|
+
) {
|
|
20
|
+
return dirtyValues[rowKeyValue][colKeyValue];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
@@ -1306,7 +1306,7 @@ export function updateRowNavigationMode(hadTreeDataTypePreviously, state) {
|
|
|
1306
1306
|
|
|
1307
1307
|
/***************************** HELPER FUNCTIONS *****************************/
|
|
1308
1308
|
|
|
1309
|
-
function isCellElement(tagName, role) {
|
|
1309
|
+
export function isCellElement(tagName, role) {
|
|
1310
1310
|
return (
|
|
1311
1311
|
SELECTORS.cell.default.includes(tagName) ||
|
|
1312
1312
|
SELECTORS.cell.roleBased.includes(role)
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { getScrollOffsetFromTableEnd } from './utils';
|
|
1
|
+
import { getScrollOffsetFromTableEnd, normalizeNumberAttribute } from './utils';
|
|
2
2
|
import { LightningResizeObserver } from 'lightning/resizeObserver';
|
|
3
|
-
import { normalizeBoolean } from 'lightning/utilsPrivate';
|
|
3
|
+
import { normalizeBoolean, normalizeString } from 'lightning/utilsPrivate';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
export const DEFAULT_ROW_HEIGHT = 30.5;
|
|
6
|
+
const DEFAULT_BUFFER_SIZE = 5;
|
|
7
|
+
const ROW_THRESHOLD = 10;
|
|
8
|
+
const DEFAULT_SCROLL_THRESHOLD = ROW_THRESHOLD * DEFAULT_ROW_HEIGHT;
|
|
9
|
+
const VERTICAL_VIRTUALIZATION = 'vertical';
|
|
8
10
|
|
|
9
11
|
export function setViewportRendering(state, value) {
|
|
10
12
|
state.enableViewportRendering = normalizeBoolean(value);
|
|
@@ -14,39 +16,27 @@ export function isViewportRenderingEnabled(state) {
|
|
|
14
16
|
return state.enableViewportRendering;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Updates and normalizes the configuration for this RenderManager
|
|
26
|
-
*
|
|
27
|
-
* @param {LightningDatatable} dt
|
|
28
|
-
* @param {RenderManager} renderManager
|
|
29
|
-
* @param {RenderManagerConfig} config
|
|
30
|
-
*
|
|
31
|
-
* @returns {RenderManager}
|
|
32
|
-
*/
|
|
33
|
-
function normalizeAndProcessConfig(dt, renderManager, config) {
|
|
34
|
-
const { viewportRendering, rowHeight } = config;
|
|
19
|
+
export function normalizeVirtualization(value) {
|
|
20
|
+
return normalizeString(value, {
|
|
21
|
+
fallbackValue: '', //no virtualization enabled
|
|
22
|
+
validValues: [VERTICAL_VIRTUALIZATION],
|
|
23
|
+
});
|
|
24
|
+
}
|
|
35
25
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
export function getDTRows() {
|
|
27
|
+
return this.state.rows;
|
|
28
|
+
}
|
|
39
29
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
30
|
+
export function getDTRenderedRowCount() {
|
|
31
|
+
return this._renderedRowCount;
|
|
32
|
+
}
|
|
44
33
|
|
|
45
|
-
|
|
34
|
+
export function setDTRenderedRowCount(renderedRowCount) {
|
|
35
|
+
this._renderedRowCount = renderedRowCount;
|
|
46
36
|
}
|
|
47
37
|
|
|
48
|
-
function
|
|
49
|
-
return
|
|
38
|
+
export function getDTWrapperHeight() {
|
|
39
|
+
return this.template.querySelector('.slds-scrollable_x').offsetHeight;
|
|
50
40
|
}
|
|
51
41
|
|
|
52
42
|
function getDefaultPreviousInfo() {
|
|
@@ -57,6 +47,13 @@ function getDefaultPreviousInfo() {
|
|
|
57
47
|
};
|
|
58
48
|
}
|
|
59
49
|
|
|
50
|
+
/**
|
|
51
|
+
* @typedef RenderManagerConfig
|
|
52
|
+
* @type {object}
|
|
53
|
+
* @property {boolean} viewportRendering - specifies whether to use viewport rendering
|
|
54
|
+
* @property {number} rowHeight - specifies the height of a row, in px
|
|
55
|
+
*/
|
|
56
|
+
|
|
60
57
|
/**
|
|
61
58
|
* Handles any custom rendering in datatable.
|
|
62
59
|
*
|
|
@@ -66,38 +63,211 @@ function getDefaultPreviousInfo() {
|
|
|
66
63
|
*/
|
|
67
64
|
export class RenderManager {
|
|
68
65
|
constructor() {
|
|
66
|
+
this.bufferSize = DEFAULT_BUFFER_SIZE;
|
|
69
67
|
this.rowHeight = DEFAULT_ROW_HEIGHT;
|
|
70
68
|
this.threshold = DEFAULT_SCROLL_THRESHOLD;
|
|
71
69
|
this.wrapperHeight = 0;
|
|
70
|
+
this.virtualize = '';
|
|
72
71
|
this.previousCache = getDefaultPreviousInfo();
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
75
|
+
* Updates and normalizes configuration for RenderManager
|
|
76
|
+
* Used when setting renderConfig for datatable
|
|
77
|
+
* @param {Function} getRows
|
|
78
|
+
* @param {Function} getWrapperHeight
|
|
79
|
+
* @param {Number} renderedRowCount
|
|
80
|
+
* @param {Function} setRenderedRowCount
|
|
78
81
|
* @param {RenderManagerConfig} config
|
|
79
82
|
*/
|
|
80
|
-
configure(
|
|
81
|
-
|
|
83
|
+
configure(
|
|
84
|
+
getRows,
|
|
85
|
+
getWrapperHeight,
|
|
86
|
+
renderedRowCount,
|
|
87
|
+
setRenderedRowCount,
|
|
88
|
+
config
|
|
89
|
+
) {
|
|
90
|
+
const { viewportRendering, rowHeight, virtualize, bufferSize } = config;
|
|
91
|
+
this.virtualize = normalizeVirtualization(virtualize);
|
|
92
|
+
if (normalizeBoolean(viewportRendering) || this.virtualize) {
|
|
93
|
+
this.initializeResizeObserver(
|
|
94
|
+
getRows,
|
|
95
|
+
getWrapperHeight,
|
|
96
|
+
renderedRowCount,
|
|
97
|
+
setRenderedRowCount
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
this.bufferSize = normalizeNumberAttribute(
|
|
101
|
+
'bufferSize',
|
|
102
|
+
bufferSize || DEFAULT_BUFFER_SIZE,
|
|
103
|
+
'non-negative',
|
|
104
|
+
DEFAULT_BUFFER_SIZE
|
|
105
|
+
);
|
|
106
|
+
if (typeof rowHeight === 'number') {
|
|
107
|
+
this.rowHeight = rowHeight;
|
|
108
|
+
this.threshold = ROW_THRESHOLD * this.rowHeight;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Render only rows that fit within the viewport
|
|
114
|
+
*
|
|
115
|
+
* If data has changed (verifying only row 1), reset everything
|
|
116
|
+
* Otherwise, if total row count has increased and we are within the scroll threshold,
|
|
117
|
+
* append a viewport's worth of rows to the currently rendered rows. This happens when
|
|
118
|
+
* the user has added more data to the datatable (e.g when a loadMore is triggered)
|
|
119
|
+
*
|
|
120
|
+
* @param {Array} rows
|
|
121
|
+
* @param {Function} setRenderedRowCount
|
|
122
|
+
* @param {Node} gridContainer
|
|
123
|
+
* @param {Boolean} forceUpdate
|
|
124
|
+
*/
|
|
125
|
+
updateViewportRendering(
|
|
126
|
+
rows,
|
|
127
|
+
setRenderedRowCount,
|
|
128
|
+
gridContainer,
|
|
129
|
+
forceUpdate
|
|
130
|
+
) {
|
|
131
|
+
if (this.hasDataChanged(rows) || forceUpdate) {
|
|
132
|
+
this.updateRenderedRows(
|
|
133
|
+
rows,
|
|
134
|
+
setRenderedRowCount,
|
|
135
|
+
this.getRowCountWithBuffer()
|
|
136
|
+
);
|
|
137
|
+
} else if (
|
|
138
|
+
this.previousCache.totalRowCount < rows.length &&
|
|
139
|
+
this.isWithinThreshold(gridContainer)
|
|
140
|
+
) {
|
|
141
|
+
this.updateRenderedRows(
|
|
142
|
+
rows,
|
|
143
|
+
setRenderedRowCount,
|
|
144
|
+
this.previousCache.renderedRowCount +
|
|
145
|
+
this.getRowCountWithBuffer()
|
|
146
|
+
);
|
|
147
|
+
} else {
|
|
148
|
+
this.updateRenderedRows(
|
|
149
|
+
rows,
|
|
150
|
+
setRenderedRowCount,
|
|
151
|
+
this.previousCache.renderedRowCount
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Handles scroll event on datatable if viewport rendering enabled
|
|
158
|
+
* If the scroll is within a specified threshold of the bottom,
|
|
159
|
+
* calculate and render the next batch of rows
|
|
160
|
+
*
|
|
161
|
+
* @param {Array} rows
|
|
162
|
+
* @param {Number} currentLength
|
|
163
|
+
* @param {Function} setRenderedRowCount
|
|
164
|
+
* @param {Event} event - scroll event
|
|
165
|
+
*/
|
|
166
|
+
handleScroll(rows, currentLength, setRenderedRowCount, event) {
|
|
167
|
+
if (
|
|
168
|
+
this.isWithinThreshold(event.target.firstChild) &&
|
|
169
|
+
currentLength < rows.length
|
|
170
|
+
) {
|
|
171
|
+
this.updateRenderedRows(
|
|
172
|
+
rows,
|
|
173
|
+
setRenderedRowCount,
|
|
174
|
+
currentLength + this.getRowCountWithBuffer()
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* gets the index of the first row that should be visible in the viewport
|
|
181
|
+
*
|
|
182
|
+
* @param {Event} event
|
|
183
|
+
* @returns {number} index of first row visible in viewport
|
|
184
|
+
*/
|
|
185
|
+
getFirstVisibleIndex(event) {
|
|
186
|
+
return event.target.scrollTop / this.rowHeight;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* calculates the range of rows that should be rendered based on the
|
|
191
|
+
* first visible index, buffer size and datatable height
|
|
192
|
+
*
|
|
193
|
+
* @param {number} firstVisibleIndex
|
|
194
|
+
* @returns {Object} object with firstIndex and lastIndex of rendered range of rows
|
|
195
|
+
*/
|
|
196
|
+
getRenderedRange(firstVisibleIndex) {
|
|
197
|
+
const firstIndex = Math.max(firstVisibleIndex - this.bufferSize, 0);
|
|
198
|
+
const lastIndex =
|
|
199
|
+
firstVisibleIndex - this.bufferSize + this.getRowCountWithBuffer();
|
|
200
|
+
|
|
201
|
+
return { firstIndex, lastIndex };
|
|
82
202
|
}
|
|
83
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Updates internal cache of row counts and first key
|
|
206
|
+
*
|
|
207
|
+
* @param {Array} rows
|
|
208
|
+
* @param {Function} setRenderedRowCount
|
|
209
|
+
* @param {Number} rowCount
|
|
210
|
+
*/
|
|
211
|
+
updateRenderedRows(rows, setRenderedRowCount, rowCount) {
|
|
212
|
+
const totalRows = rows.length;
|
|
213
|
+
const normalizedRowCount = rowCount
|
|
214
|
+
? Math.min(rowCount, totalRows)
|
|
215
|
+
: totalRows;
|
|
216
|
+
setRenderedRowCount(normalizedRowCount);
|
|
217
|
+
|
|
218
|
+
// Update our internal cache
|
|
219
|
+
this.previousCache.renderedRowCount = normalizedRowCount;
|
|
220
|
+
this.previousCache.totalRowCount = totalRows;
|
|
221
|
+
|
|
222
|
+
if (rows.length > 0) {
|
|
223
|
+
this.previousCache.firstRowKey = rows[0].key;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Caches the height of the wrapper in Datatable to avoid
|
|
229
|
+
* unnecessary reflows
|
|
230
|
+
*
|
|
231
|
+
* @param {Function} getWrapperHeight
|
|
232
|
+
*/
|
|
233
|
+
updateWrapperHeight(getWrapperHeight) {
|
|
234
|
+
this.wrapperHeight = getWrapperHeight();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/************************** OBSERVER MANAGEMENT **************************/
|
|
238
|
+
|
|
84
239
|
/**
|
|
85
240
|
* Initializes a resize observer to update the wrapper height
|
|
86
241
|
* when the datatable component's height changes
|
|
87
242
|
*
|
|
88
|
-
* @param {
|
|
243
|
+
* @param {Function} getRows
|
|
244
|
+
* @param {Function} getWrapperHeight
|
|
245
|
+
* @param {Function} getRenderedRowCount
|
|
246
|
+
* @param {Function} setRenderedRowCount
|
|
89
247
|
*/
|
|
90
|
-
initializeResizeObserver(
|
|
248
|
+
initializeResizeObserver(
|
|
249
|
+
getRows,
|
|
250
|
+
getWrapperHeight,
|
|
251
|
+
getRenderedRowCount,
|
|
252
|
+
setRenderedRowCount
|
|
253
|
+
) {
|
|
91
254
|
if (!this._heightResizeObserver) {
|
|
92
255
|
this._heightResizeObserver = new LightningResizeObserver(() => {
|
|
93
256
|
if (this._resizeObserverConnected) {
|
|
94
|
-
this.updateWrapperHeight(
|
|
257
|
+
this.updateWrapperHeight(getWrapperHeight);
|
|
95
258
|
|
|
96
|
-
// If the wrapper is now larger than the table
|
|
97
|
-
// the rendered rows so users can continue scrolling
|
|
259
|
+
// If the wrapper is now larger than the table or virtualization enabled,
|
|
260
|
+
// we need to update the rendered rows so users can continue scrolling
|
|
98
261
|
const rowCountWithBuffer = this.getRowCountWithBuffer();
|
|
99
|
-
if (
|
|
100
|
-
|
|
262
|
+
if (
|
|
263
|
+
rowCountWithBuffer > getRenderedRowCount() ||
|
|
264
|
+
this.virtualize
|
|
265
|
+
) {
|
|
266
|
+
this.updateRenderedRows(
|
|
267
|
+
getRows(),
|
|
268
|
+
setRenderedRowCount,
|
|
269
|
+
rowCountWithBuffer
|
|
270
|
+
);
|
|
101
271
|
}
|
|
102
272
|
}
|
|
103
273
|
});
|
|
@@ -107,13 +277,10 @@ export class RenderManager {
|
|
|
107
277
|
/**
|
|
108
278
|
* Connect the resize observer to the correct element
|
|
109
279
|
*
|
|
110
|
-
* @param {
|
|
280
|
+
* @param {Node} resizeTarget
|
|
111
281
|
*/
|
|
112
|
-
connectResizeObserver(
|
|
282
|
+
connectResizeObserver(resizeTarget) {
|
|
113
283
|
if (this._heightResizeObserver) {
|
|
114
|
-
const resizeTarget = dt.template.querySelector(
|
|
115
|
-
'div.dt-outer-container'
|
|
116
|
-
);
|
|
117
284
|
this._heightResizeObserver.observe(resizeTarget);
|
|
118
285
|
this._resizeObserverConnected = true;
|
|
119
286
|
}
|
|
@@ -129,104 +296,49 @@ export class RenderManager {
|
|
|
129
296
|
}
|
|
130
297
|
}
|
|
131
298
|
|
|
132
|
-
|
|
133
|
-
return !!this.wrapperHeight;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Caches the height of the wrapper in Datatable to avoid
|
|
138
|
-
* unnecessary reflows
|
|
139
|
-
*
|
|
140
|
-
* @param {LightningDatatable} dt
|
|
141
|
-
*/
|
|
142
|
-
updateWrapperHeight(dt) {
|
|
143
|
-
this.wrapperHeight =
|
|
144
|
-
dt.template.querySelector('.slds-scrollable_x').offsetHeight;
|
|
145
|
-
}
|
|
299
|
+
/************************* HELPER FUNCTIONS **************************/
|
|
146
300
|
|
|
147
301
|
/**
|
|
148
302
|
* Calculates how many rows fits within the current wrapper
|
|
149
303
|
*/
|
|
150
304
|
getRowCountInViewport() {
|
|
151
|
-
return Math.
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
getRowCountWithBuffer() {
|
|
155
|
-
return this.getRowCountInViewport() + BUFFER_ROW_COUNT;
|
|
305
|
+
return Math.ceil(this.wrapperHeight / this.rowHeight);
|
|
156
306
|
}
|
|
157
307
|
|
|
158
308
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* If data has changed (verifying only row 1), reset everything
|
|
162
|
-
* Otherwise, if total row count has increased and we are within the scroll threshold,
|
|
163
|
-
* append a viewport's worth of rows to the currently rendered rows. This happens when
|
|
164
|
-
* the user has added more data to the datatable (e.g when a loadMore is triggered)
|
|
165
|
-
*
|
|
166
|
-
* @param {LightningDatatable} dt
|
|
309
|
+
* Calculates how many rows fit in current wrapper with an added buffer
|
|
310
|
+
* Used to determine how many additional rows to render
|
|
167
311
|
*/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.isWithinThreshold(dt.template.querySelector('table'))
|
|
174
|
-
) {
|
|
175
|
-
this.updateRenderedRows(
|
|
176
|
-
dt,
|
|
177
|
-
this.previousCache.renderedRowCount +
|
|
178
|
-
this.getRowCountWithBuffer()
|
|
179
|
-
);
|
|
180
|
-
} else {
|
|
181
|
-
this.updateRenderedRows(dt, this.previousCache.renderedRowCount);
|
|
182
|
-
}
|
|
312
|
+
getRowCountWithBuffer() {
|
|
313
|
+
// buffer is before and after with virtualization
|
|
314
|
+
// but only after with viewport rendering
|
|
315
|
+
const multiplier = this.virtualize ? 2 : 1;
|
|
316
|
+
return this.getRowCountInViewport() + this.bufferSize * multiplier;
|
|
183
317
|
}
|
|
184
318
|
|
|
185
319
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* @param {LightningDatatable} dt
|
|
190
|
-
* @param {Event} event - scroll event
|
|
320
|
+
* Checks if offset is within threshold of end of table
|
|
321
|
+
* Used when determining if additional rows should be rendered
|
|
322
|
+
* @returns {boolean} true if offset is within threshold
|
|
191
323
|
*/
|
|
192
|
-
handleScroll(dt, event) {
|
|
193
|
-
const currentLength = dt._renderedRowCount;
|
|
194
|
-
if (
|
|
195
|
-
this.isWithinThreshold(event.target.firstChild) &&
|
|
196
|
-
currentLength < dt.state.rows.length
|
|
197
|
-
) {
|
|
198
|
-
this.updateRenderedRows(
|
|
199
|
-
dt,
|
|
200
|
-
currentLength + this.getRowCountWithBuffer()
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
updateRenderedRows(dt, rowCount) {
|
|
206
|
-
const totalRows = dt.state.rows.length;
|
|
207
|
-
const normalizedRowCount = rowCount
|
|
208
|
-
? Math.min(rowCount, totalRows)
|
|
209
|
-
: totalRows;
|
|
210
|
-
dt._renderedRowCount = normalizedRowCount;
|
|
211
|
-
|
|
212
|
-
// Update our internal cache
|
|
213
|
-
this.previousCache.renderedRowCount = normalizedRowCount;
|
|
214
|
-
this.previousCache.totalRowCount = totalRows;
|
|
215
|
-
|
|
216
|
-
if (dt.state.rows.length > 0) {
|
|
217
|
-
this.previousCache.firstRowKey = dt.state.rows[0].key;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
324
|
isWithinThreshold(target) {
|
|
222
325
|
const offset = getScrollOffsetFromTableEnd(target);
|
|
223
|
-
return offset
|
|
326
|
+
return offset <= this.threshold;
|
|
224
327
|
}
|
|
225
328
|
|
|
226
|
-
|
|
329
|
+
/**
|
|
330
|
+
* Checks key of first row to determine if data has changed
|
|
331
|
+
* Used to determine if viewport rendering should be reset
|
|
332
|
+
* @param {Array} rows
|
|
333
|
+
* @returns {Boolean} true if key of first row has changed
|
|
334
|
+
*/
|
|
335
|
+
hasDataChanged(rows) {
|
|
227
336
|
return (
|
|
228
|
-
|
|
229
|
-
this.previousCache.firstRowKey !== dt.state.rows[0].key
|
|
337
|
+
rows.length > 0 && this.previousCache.firstRowKey !== rows[0].key
|
|
230
338
|
);
|
|
231
339
|
}
|
|
340
|
+
|
|
341
|
+
hasWrapperHeight() {
|
|
342
|
+
return !!this.wrapperHeight;
|
|
343
|
+
}
|
|
232
344
|
}
|
|
@@ -3,39 +3,43 @@ import { getUserRowByCellKeys } from './rows';
|
|
|
3
3
|
import { getUserColumnIndex } from './columns';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
+
* Handles the `privatecellactiontriggered` event on lightning-datatable
|
|
6
7
|
*
|
|
7
|
-
* @param {CustomEvent} event -
|
|
8
|
+
* @param {CustomEvent} event - `privatecellactiontriggered`
|
|
8
9
|
*/
|
|
9
10
|
export function handleRowActionTriggered(event) {
|
|
10
|
-
|
|
11
|
+
event.stopPropagation();
|
|
12
|
+
|
|
13
|
+
const { action, colKeyValue, rowKeyValue } = event.detail;
|
|
11
14
|
const selectedRow = getUserRowByCellKeys(
|
|
12
15
|
this.state,
|
|
13
16
|
rowKeyValue,
|
|
14
17
|
colKeyValue
|
|
15
18
|
);
|
|
16
19
|
|
|
17
|
-
event.stopPropagation();
|
|
18
|
-
|
|
19
20
|
this.dispatchEvent(
|
|
20
21
|
new CustomEvent('rowaction', {
|
|
21
22
|
detail: {
|
|
22
|
-
row: unwrap(selectedRow),
|
|
23
23
|
action: unwrap(action),
|
|
24
|
+
row: unwrap(selectedRow),
|
|
24
25
|
},
|
|
25
26
|
})
|
|
26
27
|
);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
/**
|
|
31
|
+
* Handles the `privatecellactionmenuopening` event on lightning-datatable
|
|
30
32
|
*
|
|
31
|
-
* @param {CustomEvent} event -
|
|
33
|
+
* @param {CustomEvent} event - `privatecellactionmenuopening`
|
|
32
34
|
*/
|
|
33
35
|
export function handleLoadDynamicActions(event) {
|
|
36
|
+
event.stopPropagation();
|
|
37
|
+
|
|
34
38
|
const {
|
|
35
|
-
rowKeyValue,
|
|
36
|
-
colKeyValue,
|
|
37
39
|
actionsProviderFunction,
|
|
40
|
+
colKeyValue,
|
|
38
41
|
doneCallback,
|
|
42
|
+
rowKeyValue,
|
|
39
43
|
saveContainerPosition,
|
|
40
44
|
} = event.detail;
|
|
41
45
|
const selectedRow = getUserRowByCellKeys(
|
|
@@ -45,18 +49,18 @@ export function handleLoadDynamicActions(event) {
|
|
|
45
49
|
);
|
|
46
50
|
|
|
47
51
|
saveContainerPosition(this.getViewableRect());
|
|
48
|
-
|
|
49
|
-
event.stopPropagation();
|
|
50
52
|
actionsProviderFunction(unwrap(selectedRow), doneCallback);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
/**
|
|
56
|
+
* Handles the `privatecellbuttonclicked` event on lightning-datatable
|
|
54
57
|
*
|
|
55
|
-
* @param {CustomEvent} event -
|
|
58
|
+
* @param {CustomEvent} event - `privatecellbuttonclicked`
|
|
56
59
|
*/
|
|
57
60
|
export function handleCellButtonClick(event) {
|
|
58
61
|
event.stopPropagation();
|
|
59
|
-
|
|
62
|
+
|
|
63
|
+
const { colKeyValue, rowKeyValue } = event.detail;
|
|
60
64
|
const row = getUserRowByCellKeys(this.state, rowKeyValue, colKeyValue);
|
|
61
65
|
const userColumnIndex = getUserColumnIndex(this.state, colKeyValue);
|
|
62
66
|
const userColumnDefinition = this._columns[userColumnIndex];
|
|
@@ -64,8 +68,8 @@ export function handleCellButtonClick(event) {
|
|
|
64
68
|
this.dispatchEvent(
|
|
65
69
|
new CustomEvent('rowaction', {
|
|
66
70
|
detail: {
|
|
67
|
-
row: unwrap(row),
|
|
68
71
|
action: unwrap(userColumnDefinition.typeAttributes),
|
|
72
|
+
row: unwrap(row),
|
|
69
73
|
},
|
|
70
74
|
})
|
|
71
75
|
);
|