@progress/kendo-react-grid 5.11.0 → 5.11.1-dev.202302081554

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/es/Grid.d.ts CHANGED
@@ -93,6 +93,7 @@ export declare class Grid extends React.Component<GridProps, {}> {
93
93
  editField: PropTypes.Requireable<string>;
94
94
  scrollable: PropTypes.Requireable<string>;
95
95
  rowHeight: PropTypes.Requireable<number>;
96
+ detailRowHeight: PropTypes.Requireable<number>;
96
97
  detail: PropTypes.Requireable<any>;
97
98
  style: PropTypes.Requireable<object>;
98
99
  onDataStateChange: PropTypes.Requireable<(...args: any[]) => any>;
@@ -111,6 +112,7 @@ export declare class Grid extends React.Component<GridProps, {}> {
111
112
  private contextStateRef;
112
113
  private navigationStateRef;
113
114
  private _data;
115
+ private _slicedData;
114
116
  private wrapperScrollTop;
115
117
  /**
116
118
  * A getter of the current columns. Gets the current column width or current columns, or any other [`GridColumnProps`]({% slug api_grid_gridcolumnprops %}) for each defined column. Can be used on each Grid instance. To obtain the instance of the rendered Grid, use the `ref` callback. The following example demonstrates how to reorder the columns by dragging their handlers and check the properties afterwards. You can check the result in the browser console.
@@ -160,12 +162,15 @@ export declare class Grid extends React.Component<GridProps, {}> {
160
162
  private headerElementRef;
161
163
  private _element;
162
164
  private tableElement;
165
+ private containerRef;
166
+ private tableBodyRef;
163
167
  private vs;
164
168
  private columnResize;
165
169
  private _footer;
166
170
  private forceUpdateTimeout;
167
171
  private isRtl;
168
172
  private _gridId;
173
+ private _prevTotal;
169
174
  private get _header();
170
175
  constructor(props: GridProps);
171
176
  /**
@@ -202,6 +207,9 @@ export declare class Grid extends React.Component<GridProps, {}> {
202
207
  * @hidden
203
208
  */
204
209
  render(): JSX.Element;
210
+ private getVirtualScroll;
211
+ private isAllData;
212
+ private initializeVirtualization;
205
213
  private scrollHandler;
206
214
  private onKeyDown;
207
215
  private onFocus;
@@ -223,6 +231,8 @@ export declare class Grid extends React.Component<GridProps, {}> {
223
231
  private columnToGroup;
224
232
  private resetTableWidth;
225
233
  private onResize;
234
+ private flatData;
235
+ private rowHeightService;
226
236
  private childrenToArray;
227
237
  private readColumns;
228
238
  private mapColumns;
package/dist/es/Grid.js CHANGED
@@ -46,6 +46,7 @@ import { FilterRow } from './header/FilterRow';
46
46
  import { GroupPanel } from './header/GroupPanel';
47
47
  import { Footer } from './footer/Footer';
48
48
  import { VirtualScroll } from './VirtualScroll';
49
+ import { RowHeightService, VirtualScrollFixed } from './VirtualScrollFixed';
49
50
  import { ColumnResize } from './drag/ColumnResize';
50
51
  import { CommonDragLogic } from './drag/CommonDragLogic';
51
52
  import { getNestedValue, flatData, readColumns, autoGenerateColumns, firefox, firefoxMaxHeight, sanitizeColumns } from './utils/index';
@@ -103,15 +104,19 @@ var Grid = /** @class */ (function (_super) {
103
104
  _this.contextStateRef = { current: undefined };
104
105
  _this.navigationStateRef = { current: undefined };
105
106
  _this._data = [];
107
+ _this._slicedData = undefined;
106
108
  _this.wrapperScrollTop = 0;
107
109
  _this.headerRef = React.createRef();
108
110
  _this.headerElementRef = React.createRef();
109
111
  _this._element = null;
110
112
  _this.tableElement = null;
113
+ _this.containerRef = React.createRef();
114
+ _this.tableBodyRef = React.createRef();
111
115
  _this._footer = null;
112
116
  _this.forceUpdateTimeout = undefined;
113
117
  _this.isRtl = false;
114
118
  _this._gridId = guid();
119
+ _this._prevTotal = undefined;
115
120
  /**
116
121
  * Method to allow the scroll to be set to a specific row index.
117
122
  *
@@ -143,11 +148,77 @@ var Grid = /** @class */ (function (_super) {
143
148
  _this.fitColumns = function (columnIds) {
144
149
  _this.columnResize.dblClickHandler(null, columnIds);
145
150
  };
151
+ _this.getVirtualScroll = function (props) {
152
+ var rowHeight = props.rowHeight, detailRowHeight = props.detailRowHeight, detail = props.detail, expandField = props.expandField, groupable = props.groupable;
153
+ var hasAllData = _this.isAllData();
154
+ var hasRowHeight = rowHeight !== undefined && rowHeight > 0;
155
+ var hasDetailRowHeight = detailRowHeight !== undefined && detailRowHeight > 0;
156
+ var isGroupable = groupable === true || (typeof groupable === 'object' && groupable.enabled !== false);
157
+ var hasDetails = Boolean(detail && expandField);
158
+ if (!hasRowHeight ||
159
+ (isGroupable && !hasAllData) ||
160
+ (hasDetails && (!hasDetailRowHeight || !hasAllData))) {
161
+ return VirtualScroll;
162
+ }
163
+ return VirtualScrollFixed;
164
+ };
165
+ _this.isAllData = function () {
166
+ var _a = _this.props, data = _a.data, total = _a.total;
167
+ if (Array.isArray(data)) {
168
+ return data.length === total;
169
+ }
170
+ else if (data) {
171
+ return total === data.total;
172
+ }
173
+ return false;
174
+ };
175
+ _this.initializeVirtualization = function (total, groupable) {
176
+ if (_this.props.total !== _this._prevTotal || (_this.props.scrollable === 'virtual') !== _this.vs.scrollableVirtual) {
177
+ _this.vs.reset();
178
+ var VS = _this.getVirtualScroll(_this.props);
179
+ _this.vs = new VS(groupable || _this.props.rowHeight === undefined || _this.props.rowHeight === 0);
180
+ }
181
+ _this.vs.fixedScroll = _this.props.fixedScroll || false;
182
+ _this.vs.PageChange = _this.pageChange;
183
+ _this.vs.realSkip = _this.props.skip || 0;
184
+ _this.vs.pageSize = (_this.props.take !== undefined ? _this.props.take : _this.props.pageSize) || 0;
185
+ _this.vs.scrollableVirtual = (_this.props.scrollable === 'virtual');
186
+ _this.vs.total = total;
187
+ _this.vs.propsSkip = (_this.props.skip || 0) + (_this.props.scrollable === 'virtual' ?
188
+ _this.vs.topCacheCount + (_this.vs.attendedSkip - (_this.props.skip || 0)) : 0);
189
+ if (_this.props.rowHeight !== undefined && _this.props.rowHeight > 0 && !groupable) {
190
+ var containerHeight = _this.props.rowHeight * total;
191
+ _this.vs.containerHeight = firefox ? Math.min(firefoxMaxHeight, containerHeight) : containerHeight;
192
+ }
193
+ else {
194
+ _this.vs.containerHeight = 1533915;
195
+ }
196
+ _this.vs.containerRef = _this.containerRef;
197
+ _this.vs.tableBodyRef = _this.tableBodyRef;
198
+ _this.vs.table = _this.tableElement;
199
+ _this._slicedData = undefined;
200
+ if (_this.vs instanceof VirtualScrollFixed) {
201
+ var _a = _this.props, _b = _a.rowHeight, rowHeight = _b === void 0 ? 0 : _b, detail = _a.detail, expandField = _a.expandField;
202
+ var _c = _this.props.detailRowHeight, detailRowHeight = _c === void 0 ? 0 : _c;
203
+ detailRowHeight = Boolean(detail && expandField) ? detailRowHeight : rowHeight;
204
+ if (_this.isAllData()) {
205
+ _this.vs.total = _this._data.length;
206
+ _this._slicedData = _this._data.slice(_this.vs.realSkip, _this.vs.realSkip + _this.vs.pageSize);
207
+ _this.vs.rowHeightService = _this.rowHeightService(_this.vs, _this._data.length, rowHeight, detailRowHeight, _this._data);
208
+ }
209
+ else {
210
+ _this.vs.rowHeightService = new RowHeightService(total, rowHeight, detailRowHeight);
211
+ }
212
+ var containerHeight = _this.vs.rowHeightService.totalHeight();
213
+ _this.vs.containerHeight = firefox ? Math.min(firefoxMaxHeight, containerHeight) : containerHeight;
214
+ }
215
+ };
146
216
  _this.scrollHandler = function (event) {
147
217
  if (event.target !== event.currentTarget) {
148
218
  return;
149
219
  }
150
220
  clearTimeout(_this.forceUpdateTimeout);
221
+ _this.vs.table = _this.tableElement;
151
222
  var scrollLeft = event.currentTarget.scrollLeft;
152
223
  var scrollTop = event.currentTarget.scrollTop;
153
224
  if (_this.props.columnVirtualization && (!_this.vs.scrollableVirtual || scrollTop === _this.wrapperScrollTop)) {
@@ -262,6 +333,14 @@ var Grid = /** @class */ (function (_super) {
262
333
  });
263
334
  }
264
335
  };
336
+ _this.flatData = memoizeOne(function (propsData, groupingFooter, skip, group, expandField, _filter, _sort) {
337
+ var flattedData = [];
338
+ var resolvedGroupsCount = flatData(flattedData, propsData, groupingFooter, { index: skip }, group !== undefined, expandField);
339
+ return { flattedData: flattedData, resolvedGroupsCount: resolvedGroupsCount };
340
+ });
341
+ _this.rowHeightService = memoizeOne(function (_vs, total, rowHeight, detailRowHeight, data) {
342
+ return new RowHeightService(total, rowHeight, detailRowHeight, data);
343
+ });
265
344
  _this.childrenToArray = memoizeOne(function (children) {
266
345
  return React.Children.toArray(children);
267
346
  });
@@ -311,7 +390,7 @@ var Grid = /** @class */ (function (_super) {
311
390
  columns.slice(columnIndexOffset).forEach(function (c) { return c.parentIndex >= 0 && (c.parentIndex += columnIndexOffset); });
312
391
  });
313
392
  _this.getHeaderRow = memoizeOne(function (sort, sortable, group, groupable, filter, filterable, filterOperators, headerCellRender, columnMenu, columns, columnsMap) {
314
- return (React.createElement(HeaderRow, { sort: sort, sortable: sortable, sortChange: _this.sortChange, group: group || [], groupable: groupable, groupChange: _this.groupChange, filter: filter, filterable: filterable, filterOperators: filterOperators, filterChange: _this.filterChange, columnMenu: columnMenu, selectionChange: _this.onHeaderSelectionChange, columns: columns, columnResize: _this.columnResize, pressHandler: _this.dragLogic.pressHandler, dragHandler: _this.dragLogic.dragHandler, releaseHandler: _this.dragLogic.releaseHandler, columnsMap: columnsMap, cellRender: headerCellRender, isRtl: _this.isRtl, dragClue: _this.dragLogic.dragClueRef, headerRef: _this.headerElementRef, containerRef: _this.vs.containerRef }));
393
+ return (React.createElement(HeaderRow, { sort: sort, sortable: sortable, sortChange: _this.sortChange, group: group || [], groupable: groupable, groupChange: _this.groupChange, filter: filter, filterable: filterable, filterOperators: filterOperators, filterChange: _this.filterChange, columnMenu: columnMenu, selectionChange: _this.onHeaderSelectionChange, columns: columns, columnResize: _this.columnResize, pressHandler: _this.dragLogic.pressHandler, dragHandler: _this.dragLogic.dragHandler, releaseHandler: _this.dragLogic.releaseHandler, columnsMap: columnsMap, cellRender: headerCellRender, isRtl: _this.isRtl, dragClue: _this.dragLogic.dragClueRef, headerRef: _this.headerElementRef, containerRef: _this.containerRef }));
315
394
  });
316
395
  _this.resolveTitle = function (field) {
317
396
  var column = _this._columns.find(function (c) { return c.field === field; });
@@ -324,7 +403,8 @@ var Grid = /** @class */ (function (_super) {
324
403
  validatePackage(packageMetadata);
325
404
  var groupable = _this.props.groupable === true ||
326
405
  (typeof _this.props.groupable === 'object') && _this.props.groupable.enabled !== false;
327
- _this.vs = new VirtualScroll(groupable || props.rowHeight === undefined || props.rowHeight === 0);
406
+ var VS = _this.getVirtualScroll(props);
407
+ _this.vs = new VS(groupable || props.rowHeight === undefined || props.rowHeight === 0);
328
408
  _this.dragLogic = new CommonDragLogic(_this.columnReorder.bind(_this), _this.groupReorder.bind(_this), _this.columnToGroup.bind(_this));
329
409
  _this.columnResize = new ColumnResize(_this.onResize);
330
410
  tableKeyboardNavigation.onConstructor({
@@ -415,9 +495,11 @@ var Grid = /** @class */ (function (_super) {
415
495
  * @hidden
416
496
  */
417
497
  Grid.prototype.componentDidMount = function () {
498
+ this.resetTableWidth();
418
499
  setScrollbarWidth();
419
500
  var rtl = isRtl(this.element);
420
501
  this.isRtl = rtl;
502
+ this._prevTotal = this.props.total;
421
503
  tableKeyboardNavigation.onComponentDidMount({
422
504
  scope: this.element || undefined,
423
505
  contextStateRef: this.contextStateRef,
@@ -443,6 +525,11 @@ var Grid = /** @class */ (function (_super) {
443
525
  */
444
526
  Grid.prototype.componentDidUpdate = function () {
445
527
  setScrollbarWidth();
528
+ this._prevTotal = this.props.total;
529
+ if (this.vs.tableTransform && this.vs.table) {
530
+ this.vs.table.style.transform = this.vs.tableTransform;
531
+ this.vs.tableTransform = '';
532
+ }
446
533
  tableKeyboardNavigation.onComponentDidUpdate({
447
534
  scope: this.element || undefined,
448
535
  contextStateRef: this.contextStateRef,
@@ -472,35 +559,16 @@ var Grid = /** @class */ (function (_super) {
472
559
  propsData = this.props.data.data;
473
560
  total = total || this.props.data.total;
474
561
  }
562
+ var groupingFooter = (typeof this.props.groupable === 'object') && this.props.groupable.footer || 'none';
563
+ var _d = this.flatData(propsData, groupingFooter, this.props.skip || 0, this.props.group, this.props.expandField, this.props.filter, this.props.sort), resolvedGroupsCount = _d.resolvedGroupsCount, flattedData = _d.flattedData;
564
+ this._data = flattedData;
475
565
  var groupable = this.props.groupable === true ||
476
566
  (typeof this.props.groupable === 'object') && this.props.groupable.enabled !== false;
477
567
  this.columnResize.resizable = this.props.resizable || false;
478
568
  this.dragLogic.reorderable = this.props.reorderable || false;
479
569
  this.dragLogic.groupable = groupable;
480
570
  var tableUserSelect = this.props.selectable && this.props.selectable.drag ? 'none' : undefined;
481
- if (total !== this.vs.total || (this.props.scrollable === 'virtual') !== this.vs.scrollableVirtual) {
482
- this.vs.reset();
483
- this.vs = new VirtualScroll(groupable || this.props.rowHeight === undefined || this.props.rowHeight === 0);
484
- this.vs.table = this.tableElement;
485
- }
486
- this.vs.fixedScroll = this.props.fixedScroll || false;
487
- this.vs.PageChange = this.pageChange;
488
- this.vs.realSkip = this.props.skip || 0;
489
- this.vs.pageSize = (this.props.take !== undefined ? this.props.take : this.props.pageSize) || 0;
490
- this.vs.scrollableVirtual = (this.props.scrollable === 'virtual');
491
- this.vs.total = total;
492
- this.vs.propsSkip = (this.props.skip || 0) + (this.props.scrollable === 'virtual' ?
493
- this.vs.topCacheCount + (this.vs.attendedSkip - (this.props.skip || 0)) : 0);
494
- if (this.props.rowHeight !== undefined && this.props.rowHeight > 0 && !groupable) {
495
- var containerHeight = this.props.rowHeight * total;
496
- this.vs.containerHeight = firefox ? Math.min(firefoxMaxHeight, containerHeight) : containerHeight;
497
- }
498
- else {
499
- this.vs.containerHeight = 1533915;
500
- }
501
- var groupingFooter = (typeof this.props.groupable === 'object') && this.props.groupable.footer || 'none';
502
- this._data = [];
503
- var resolvedGroupsCount = flatData(this._data, propsData, groupingFooter, { index: this.props.skip || 0 }, this.props.group !== undefined, this.props.expandField);
571
+ this.initializeVirtualization(total, groupable);
504
572
  var children = this.childrenToArray(this.props.children);
505
573
  this.initColumns(children, resolvedGroupsCount);
506
574
  var toolbar = children.filter(function (child) { return child && child.type &&
@@ -509,17 +577,17 @@ var Grid = /** @class */ (function (_super) {
509
577
  child.type.displayName === 'KendoReactGridNoRecords'; });
510
578
  var leafColumns = this._columns.filter(function (c) { return c.children.length === 0; });
511
579
  var groupingPanel = groupable && (React.createElement(GroupPanel, { group: this.props.group || [], groupChange: this.groupChange, pressHandler: this.dragLogic.pressHandler, dragHandler: this.dragLogic.dragHandler, releaseHandler: this.dragLogic.releaseHandler, refCallback: this.dragLogic.refGroupPanelDiv, resolveTitle: this.resolveTitle }));
512
- var _d = this.props, sort = _d.sort, sortable = _d.sortable, group = _d.group, filter = _d.filter, filterable = _d.filterable, _e = _d.filterOperators, filterOperators = _e === void 0 ? operators : _e, headerCellRender = _d.headerCellRender, columnMenu = _d.columnMenu;
580
+ var _e = this.props, sort = _e.sort, sortable = _e.sortable, group = _e.group, filter = _e.filter, filterable = _e.filterable, _f = _e.filterOperators, filterOperators = _f === void 0 ? operators : _f, headerCellRender = _e.headerCellRender, columnMenu = _e.columnMenu;
513
581
  var header = (React.createElement(Header, { size: this.props.size, columnResize: this.columnResize, staticHeaders: this.props.scrollable !== 'none', scrollableDataElement: function () { return _this.vs.container; }, draggable: this.props.reorderable || groupable, ref: this.headerRef, elemRef: this.headerElementRef, headerRow: this.getHeaderRow(sort, sortable, group, groupable, filter, filterable, filterOperators, headerCellRender, columnMenu, this._columns, this._columnsMap), filterRow: this.props.filterable && React.createElement(FilterRow, { size: this.props.size, columns: this._columns, filter: this.props.filter, filterOperators: this.props.filterOperators || operators, filterChange: this.filterChange, sort: this.props.sort, cellRender: this.props.filterCellRender, isRtl: this.isRtl, ariaRowIndex: this._columnsMap.length + 1 }) || undefined, cols: leafColumns.map(function (column, index) { return (React.createElement("col", { key: index.toString(), width: column.width !== undefined ?
514
582
  Math.floor(parseFloat(column.width.toString())) + 'px' : undefined })); }) }));
515
583
  var scrollLeft = this.vs && this.vs.container && this.vs.container.scrollLeft || 0;
516
584
  var tableWidth = parseFloat(((this.props.style || {}).width || '').toString());
517
- var _f = tableColumnsVirtualization({
585
+ var _g = tableColumnsVirtualization({
518
586
  enabled: this.props.columnVirtualization,
519
587
  columns: leafColumns,
520
588
  tableViewPortWidth: tableWidth,
521
589
  scrollLeft: scrollLeft
522
- }), colSpans = _f.colSpans, isColHidden = _f.hiddenColumns;
590
+ }), colSpans = _g.colSpans, isColHidden = _g.hiddenColumns;
523
591
  var dataRow = function (item, rowId, rowDataIndex) {
524
592
  var isInEdit = false;
525
593
  var selectedValue = _this.props.selectedField ? getNestedValue(_this.props.selectedField, item.dataItem) : undefined;
@@ -572,21 +640,21 @@ var Grid = /** @class */ (function (_super) {
572
640
  var hidden = function (index) {
573
641
  return (index >= _this._data.length - hiddenRows);
574
642
  };
575
- var absoluteDataIndex = this.vs.propsSkip || 0;
643
+ var absoluteDataIndex = this.vs.realSkip || 0;
576
644
  var body = [];
577
645
  var rowIndexStart = this._columnsMap.length + (this.props.filterable ? 1 : 0) + 1;
578
646
  var currentAriaRowIndex = 0;
579
647
  if (this._data.length) {
580
648
  var dataIndex_1 = -1;
581
649
  var detailRowCount_1 = 0;
582
- this._data.forEach(function (item, rowIndex) {
650
+ (this._slicedData || this._data).forEach(function (item, rowIndex) {
583
651
  if (item.rowType === 'data') {
584
652
  absoluteDataIndex++;
585
653
  dataIndex_1++;
586
654
  }
587
655
  var isAlt = absoluteDataIndex % 2 === 0;
588
656
  var dataItemKey = _this.props.dataItemKey && getter(_this.props.dataItemKey)(item.dataItem);
589
- var absoluteIndex = rowIndex + (_this.vs.propsSkip || 0);
657
+ var absoluteIndex = rowIndex + (_this.vs.realSkip || 0);
590
658
  var rowId = dataItemKey ? dataItemKey : 'ai' + absoluteIndex;
591
659
  var detailRowId = rowId + '_1';
592
660
  var gridRow = dataRow(item, rowId, dataIndex_1);
@@ -598,7 +666,7 @@ var Grid = /** @class */ (function (_super) {
598
666
  - (_this.props.group ? _this.props.group.length : 0)) || 1;
599
667
  detailRowCount_1++;
600
668
  currentAriaRowIndex = absoluteIndex + rowIndexStart + detailRowCount_1;
601
- body.push((React.createElement("tr", { key: detailRowId, className: classNames('k-table-row', isAlt ? 'k-detail-row k-table-alt-row k-alt' : 'k-detail-row'), style: { visibility: hidden(rowIndex) ? 'hidden' : '' }, role: "row", "aria-rowindex": currentAriaRowIndex },
669
+ body.push((React.createElement("tr", { key: detailRowId, className: classNames('k-table-row', isAlt ? 'k-detail-row k-table-alt-row k-alt' : 'k-detail-row'), style: { visibility: hidden(rowIndex) ? 'hidden' : '', height: _this.props.detailRowHeight }, role: "row", "aria-rowindex": currentAriaRowIndex },
602
670
  _this.props.group && _this.props.group.map(function (gr, idx) {
603
671
  var _a;
604
672
  var columnStyle = (_a = gridRow === null || gridRow === void 0 ? void 0 : gridRow.row[idx]) === null || _a === void 0 ? void 0 : _a.props.style;
@@ -642,9 +710,7 @@ var Grid = /** @class */ (function (_super) {
642
710
  toolbar,
643
711
  groupingPanel,
644
712
  React.createElement(TableSelection, { selectable: this.props.selectable, onRelease: this.selectionRelease, childRef: function (table) {
645
- _this.vs.table = table;
646
713
  _this.tableElement = table;
647
- _this.resetTableWidth();
648
714
  } },
649
715
  React.createElement("table", { style: { userSelect: tableUserSelect, display: tableDisplay } },
650
716
  colGroups,
@@ -671,16 +737,14 @@ var Grid = /** @class */ (function (_super) {
671
737
  _b['k-grid-virtual'] = this.props.scrollable === 'virtual',
672
738
  _b), this.props.className), ref: function (el) {
673
739
  _this._element = el;
674
- _this.resetTableWidth();
675
740
  }, role: "grid", "aria-colcount": leafColumns.length, "aria-rowcount": total, "aria-label": this.props.ariaLabel, onKeyDown: this.onKeyDown, onFocus: this.onFocus }, tableKeyboardNavigationScopeAttributes),
676
741
  toolbar,
677
742
  groupingPanel,
678
743
  header,
679
744
  React.createElement("div", { className: "k-grid-container", role: "presentation" },
680
- React.createElement("div", { ref: this.vs.containerRef, className: "k-grid-content k-virtual-content", onScroll: this.scrollHandler, role: "presentation" },
745
+ React.createElement("div", { ref: this.containerRef, className: "k-grid-content k-virtual-content", onScroll: this.scrollHandler, role: "presentation" },
681
746
  React.createElement("div", { className: 'k-grid-table-wrap', role: "presentation" },
682
747
  React.createElement(TableSelection, { selectable: this.props.selectable, onRelease: this.selectionRelease, childRef: function (table) {
683
- _this.vs.table = table;
684
748
  _this.tableElement = table;
685
749
  } },
686
750
  React.createElement("table", { className: classNames('k-table k-grid-table', (_c = {
@@ -689,9 +753,7 @@ var Grid = /** @class */ (function (_super) {
689
753
  _c["k-table-".concat(kendoThemeMaps.sizeMap[this.props.size] || this.props.size)] = this.props.size,
690
754
  _c), this.props.className), role: "presentation", style: { userSelect: tableUserSelect, display: tableDisplay } },
691
755
  colGroups,
692
- React.createElement("tbody", __assign({ className: 'k-table-tbody', ref: function (tableBody) {
693
- _this.vs.tableBody = tableBody;
694
- }, role: 'rowgroup' }, tableKeyboardNavigationBodyAttributes), body)))),
756
+ React.createElement("tbody", __assign({ className: 'k-table-tbody', ref: this.tableBodyRef, role: 'rowgroup' }, tableKeyboardNavigationBodyAttributes), body)))),
695
757
  React.createElement("div", { className: "k-height-container", role: "presentation" },
696
758
  React.createElement("div", { style: this.props.scrollable === 'virtual' ?
697
759
  { 'height': (this.vs.containerHeight) + 'px' } : {} })))),
@@ -783,8 +845,8 @@ var Grid = /** @class */ (function (_super) {
783
845
  if (this._footer) {
784
846
  this._footer.setWidth(totalWidth);
785
847
  }
786
- if (this.vs.table) {
787
- this.vs.table.style.width = totalWidth + 'px';
848
+ if (this.tableElement) {
849
+ this.tableElement.style.width = totalWidth + 'px';
788
850
  }
789
851
  };
790
852
  Grid.prototype.initColumns = function (children, groupCount) {
@@ -885,6 +947,7 @@ var Grid = /** @class */ (function (_super) {
885
947
  editField: PropTypes.string,
886
948
  scrollable: PropTypes.oneOf(['none', 'scrollable', 'virtual']),
887
949
  rowHeight: PropTypes.number,
950
+ detailRowHeight: PropTypes.number,
888
951
  detail: PropTypes.any,
889
952
  style: PropTypes.object,
890
953
  onDataStateChange: PropTypes.func,
@@ -1,9 +1,11 @@
1
1
  import { Page } from './paging/Page';
2
2
  import * as React from 'react';
3
+ import { VirtualScrollInterface } from './interfaces/VirtualScrollInterface';
4
+ import { RowHeightService } from './VirtualScrollFixed';
3
5
  /**
4
6
  * @hidden
5
7
  */
6
- export declare class VirtualScroll {
8
+ export declare class VirtualScroll implements VirtualScrollInterface {
7
9
  table: HTMLTableElement | null;
8
10
  containerHeight: number;
9
11
  topCacheCount: number;
@@ -14,16 +16,18 @@ export declare class VirtualScroll {
14
16
  realSkip: number;
15
17
  pageSize: number;
16
18
  PageChange: ((event: Page, syntheticEvent: React.SyntheticEvent<any>) => void) | null;
17
- tableBody: HTMLTableSectionElement | null;
18
- heightContainer: null;
19
+ tableBodyRef: React.RefObject<HTMLTableSectionElement>;
19
20
  fixedScroll: boolean;
20
21
  askedSkip: number | undefined;
21
22
  containerRef: React.RefObject<HTMLDivElement>;
23
+ tableTransform: string;
22
24
  get container(): HTMLDivElement | null;
23
25
  private prevScrollPos;
24
26
  private tableTranslate;
25
27
  private scrollSyncing;
28
+ private reactVersion;
26
29
  constructor(cached: boolean);
30
+ rowHeightService?: RowHeightService;
27
31
  /**
28
32
  * @return - The row heights in an array.
29
33
  */
@@ -32,7 +36,7 @@ export declare class VirtualScroll {
32
36
  acc: number;
33
37
  }>;
34
38
  changePage(skip: number, e: React.SyntheticEvent<HTMLDivElement>): void;
35
- translate(dY: number): void;
39
+ translate(dY: number, forceSet?: boolean): void;
36
40
  reset(): void;
37
41
  localScrollUp(e: React.SyntheticEvent<HTMLDivElement>): void;
38
42
  localScrollDown(e: React.SyntheticEvent<HTMLDivElement>): void;
@@ -15,14 +15,15 @@ var VirtualScroll = /** @class */ (function () {
15
15
  this.realSkip = 0;
16
16
  this.pageSize = 0;
17
17
  this.PageChange = null;
18
- this.tableBody = null;
19
- this.heightContainer = null;
18
+ this.tableBodyRef = React.createRef();
20
19
  this.fixedScroll = false;
21
20
  this.askedSkip = undefined;
22
21
  this.containerRef = React.createRef();
22
+ this.tableTransform = '';
23
23
  this.prevScrollPos = 0;
24
24
  this.tableTranslate = 0;
25
25
  this.scrollSyncing = false;
26
+ this.reactVersion = Number.parseFloat(React.version);
26
27
  this.topItems = function (heights, skipTopBuffer) {
27
28
  if (!_this.container || skipTopBuffer) {
28
29
  return { topItemsCount: 0, topItemsHeight: 0 };
@@ -65,7 +66,7 @@ var VirtualScroll = /** @class */ (function () {
65
66
  */
66
67
  get: function () {
67
68
  var result = [];
68
- var allRows = this.tableBody && this.tableBody.children || [];
69
+ var allRows = this.tableBodyRef.current && this.tableBodyRef.current.children || [];
69
70
  var accumulate = 0;
70
71
  for (var i = 0; i < allRows.length; i++) {
71
72
  if (allRows[i].className.indexOf('k-grouping-row') > -1) {
@@ -97,10 +98,15 @@ var VirtualScroll = /** @class */ (function () {
97
98
  }, e);
98
99
  }
99
100
  };
100
- VirtualScroll.prototype.translate = function (dY) {
101
+ VirtualScroll.prototype.translate = function (dY, forceSet) {
101
102
  this.tableTranslate = dY;
102
103
  if (this.scrollableVirtual && this.table) {
103
- this.table.style.transform = 'translateY(' + dY + 'px)';
104
+ if (this.reactVersion <= 17 || forceSet) {
105
+ this.table.style.transform = 'translateY(' + dY + 'px)';
106
+ }
107
+ else {
108
+ this.tableTransform = 'translateY(' + dY + 'px)';
109
+ }
104
110
  }
105
111
  };
106
112
  VirtualScroll.prototype.reset = function () {
@@ -111,7 +117,7 @@ var VirtualScroll = /** @class */ (function () {
111
117
  if (this.container) {
112
118
  this.container.scrollTop = 0;
113
119
  }
114
- this.translate(0);
120
+ this.translate(0, true);
115
121
  };
116
122
  VirtualScroll.prototype.localScrollUp = function (e) {
117
123
  if (!this.container) {
@@ -0,0 +1,49 @@
1
+ import { Page } from './paging/Page';
2
+ import * as React from 'react';
3
+ import { VirtualScrollInterface } from './interfaces/VirtualScrollInterface';
4
+ import { DataItemWrapper } from './utils';
5
+ /**
6
+ * @hidden
7
+ */
8
+ export declare class RowHeightService {
9
+ private total;
10
+ private offsets;
11
+ private heights;
12
+ constructor(total: number, rowHeight: number, detailRowHeight: number, data?: DataItemWrapper[]);
13
+ height(rowIndex: number): number;
14
+ index(position: number): number | undefined;
15
+ offset(rowIndex: number): number;
16
+ totalHeight(): number;
17
+ }
18
+ /**
19
+ * @hidden
20
+ */
21
+ export declare class VirtualScrollFixed implements VirtualScrollInterface {
22
+ table: HTMLTableElement | null;
23
+ containerHeight: number;
24
+ topCacheCount: number;
25
+ attendedSkip: number;
26
+ propsSkip: number;
27
+ total: number;
28
+ scrollableVirtual: boolean;
29
+ realSkip: number;
30
+ pageSize: number;
31
+ PageChange: ((event: Page, syntheticEvent: React.SyntheticEvent<any>) => void) | null;
32
+ tableBodyRef: React.RefObject<HTMLTableSectionElement>;
33
+ fixedScroll: boolean;
34
+ askedSkip: number | undefined;
35
+ containerRef: React.RefObject<HTMLDivElement>;
36
+ tableTransform: string;
37
+ rowHeightService?: RowHeightService;
38
+ private scrollSyncing;
39
+ private lastLoaded;
40
+ private firstLoaded;
41
+ private lastScrollTop;
42
+ private reactVersion;
43
+ get container(): HTMLDivElement | null;
44
+ constructor(_cached: boolean);
45
+ translate(dY: number, forceSet?: boolean): void;
46
+ changePage(skip: number, e: React.SyntheticEvent<HTMLDivElement>): void;
47
+ reset(): void;
48
+ scrollHandler(e: React.SyntheticEvent<HTMLDivElement>): void;
49
+ }
@@ -0,0 +1,152 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @hidden
4
+ */
5
+ var RowHeightService = /** @class */ (function () {
6
+ function RowHeightService(total, rowHeight, detailRowHeight, data) {
7
+ if (total === void 0) { total = 0; }
8
+ this.total = total;
9
+ this.offsets = [];
10
+ this.heights = [];
11
+ var agg = 0;
12
+ for (var idx = 0; idx < total; idx++) {
13
+ this.offsets.push(agg);
14
+ var currHeight = (data && data[idx].expanded && data[idx].rowType === 'data') ? detailRowHeight : rowHeight;
15
+ agg += currHeight;
16
+ this.heights.push(currHeight);
17
+ }
18
+ }
19
+ RowHeightService.prototype.height = function (rowIndex) {
20
+ return this.heights[rowIndex];
21
+ };
22
+ RowHeightService.prototype.index = function (position) {
23
+ if (position < 0) {
24
+ return undefined;
25
+ }
26
+ var result = this.offsets.reduce(function (prev, current, idx) {
27
+ if (prev !== undefined) {
28
+ return prev;
29
+ }
30
+ else if (current === position) {
31
+ return idx;
32
+ }
33
+ else if (current > position) {
34
+ return idx - 1;
35
+ }
36
+ return undefined;
37
+ }, undefined);
38
+ return result === undefined ? this.total - 1 : result;
39
+ };
40
+ RowHeightService.prototype.offset = function (rowIndex) {
41
+ return this.offsets[rowIndex];
42
+ };
43
+ RowHeightService.prototype.totalHeight = function () {
44
+ var lastOffset = this.offsets[this.offsets.length - 1];
45
+ var lastHeight = this.heights[this.heights.length - 1];
46
+ return lastOffset + lastHeight;
47
+ // return this.heights.reduce((prev, curr) => prev + curr, 0);
48
+ };
49
+ return RowHeightService;
50
+ }());
51
+ export { RowHeightService };
52
+ /**
53
+ * @hidden
54
+ */
55
+ var VirtualScrollFixed = /** @class */ (function () {
56
+ function VirtualScrollFixed(_cached) {
57
+ this.table = null;
58
+ this.containerHeight = 0;
59
+ this.topCacheCount = 0;
60
+ this.attendedSkip = 0;
61
+ this.propsSkip = 0;
62
+ this.total = 0;
63
+ this.scrollableVirtual = false;
64
+ this.realSkip = 0;
65
+ this.pageSize = 0;
66
+ this.PageChange = null;
67
+ this.tableBodyRef = React.createRef();
68
+ this.fixedScroll = false;
69
+ this.askedSkip = undefined;
70
+ this.containerRef = React.createRef();
71
+ this.tableTransform = '';
72
+ this.scrollSyncing = false;
73
+ this.lastLoaded = 0;
74
+ this.firstLoaded = 0;
75
+ this.lastScrollTop = 0;
76
+ this.reactVersion = Number.parseFloat(React.version);
77
+ this.firstLoaded = this.pageSize;
78
+ this.lastLoaded = this.realSkip + this.pageSize;
79
+ this.scrollHandler = this.scrollHandler.bind(this);
80
+ }
81
+ Object.defineProperty(VirtualScrollFixed.prototype, "container", {
82
+ get: function () {
83
+ return this.containerRef.current;
84
+ },
85
+ enumerable: false,
86
+ configurable: true
87
+ });
88
+ VirtualScrollFixed.prototype.translate = function (dY, forceSet) {
89
+ if (this.scrollableVirtual && this.table) {
90
+ if (this.reactVersion <= 17 || forceSet) {
91
+ this.table.style.transform = 'translateY(' + dY + 'px)';
92
+ }
93
+ else {
94
+ this.tableTransform = 'translateY(' + dY + 'px)';
95
+ }
96
+ }
97
+ };
98
+ VirtualScrollFixed.prototype.changePage = function (skip, e) {
99
+ if (this.PageChange) {
100
+ this.PageChange({ skip: Math.max(0, skip), take: this.pageSize }, e);
101
+ }
102
+ };
103
+ VirtualScrollFixed.prototype.reset = function () {
104
+ this.scrollSyncing = true;
105
+ if (this.fixedScroll) {
106
+ return;
107
+ }
108
+ if (this.container) {
109
+ this.container.scrollTop = 0;
110
+ }
111
+ this.translate(0, true);
112
+ };
113
+ VirtualScrollFixed.prototype.scrollHandler = function (e) {
114
+ if (!this.scrollableVirtual || !this.container || !this.table ||
115
+ !this.rowHeightService || !this.containerRef.current) {
116
+ return;
117
+ }
118
+ if (this.scrollSyncing) {
119
+ this.scrollSyncing = false;
120
+ return;
121
+ }
122
+ var scrollTop = this.container.scrollTop;
123
+ var up = this.lastScrollTop >= scrollTop;
124
+ var down = !up;
125
+ this.lastScrollTop = scrollTop;
126
+ var firstItemIndex = this.rowHeightService.index(scrollTop);
127
+ var firstItemOffset = this.rowHeightService.offset(firstItemIndex);
128
+ var offsetHeight = this.containerRef.current.offsetHeight;
129
+ var lastItemIndex = this.rowHeightService.index(scrollTop + offsetHeight);
130
+ if (down && lastItemIndex >= this.lastLoaded && this.lastLoaded < this.total) {
131
+ var overflow = (firstItemIndex + this.pageSize) - this.total;
132
+ if (overflow > 0) {
133
+ firstItemIndex = firstItemIndex - overflow;
134
+ firstItemOffset = this.rowHeightService.offset(firstItemIndex);
135
+ }
136
+ this.firstLoaded = firstItemIndex;
137
+ this.translate(firstItemOffset);
138
+ var nextTake = this.firstLoaded + this.pageSize;
139
+ this.lastLoaded = Math.min(nextTake, this.total);
140
+ this.changePage(this.firstLoaded, e);
141
+ }
142
+ else if (up && firstItemIndex < this.firstLoaded) {
143
+ var nonVisibleBuffer = Math.floor(this.pageSize * 0.3);
144
+ this.firstLoaded = Math.max(firstItemIndex - nonVisibleBuffer, 0);
145
+ this.translate(this.rowHeightService.offset(this.firstLoaded));
146
+ this.lastLoaded = Math.min(this.firstLoaded + this.pageSize, this.total);
147
+ this.changePage(this.firstLoaded, e);
148
+ }
149
+ };
150
+ return VirtualScrollFixed;
151
+ }());
152
+ export { VirtualScrollFixed };