@vaadin/vaadin-grid 21.0.4 → 21.0.5
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/package.json +10 -10
- package/src/vaadin-grid.js +62 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/vaadin-grid",
|
|
3
|
-
"version": "21.0.
|
|
3
|
+
"version": "21.0.5",
|
|
4
4
|
"description": "A free, flexible and high-quality Web Component for showing large amounts of tabular data",
|
|
5
5
|
"main": "vaadin-grid.js",
|
|
6
6
|
"module": "vaadin-grid.js",
|
|
@@ -32,23 +32,23 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@polymer/polymer": "^3.0.0",
|
|
35
|
-
"@vaadin/vaadin-checkbox": "^21.0.
|
|
36
|
-
"@vaadin/vaadin-element-mixin": "^21.0.
|
|
37
|
-
"@vaadin/vaadin-lumo-styles": "^21.0.
|
|
38
|
-
"@vaadin/vaadin-material-styles": "^21.0.
|
|
39
|
-
"@vaadin/vaadin-text-field": "^21.0.
|
|
40
|
-
"@vaadin/vaadin-themable-mixin": "^21.0.
|
|
41
|
-
"@vaadin/vaadin-virtual-list": "^21.0.
|
|
35
|
+
"@vaadin/vaadin-checkbox": "^21.0.5",
|
|
36
|
+
"@vaadin/vaadin-element-mixin": "^21.0.5",
|
|
37
|
+
"@vaadin/vaadin-lumo-styles": "^21.0.5",
|
|
38
|
+
"@vaadin/vaadin-material-styles": "^21.0.5",
|
|
39
|
+
"@vaadin/vaadin-text-field": "^21.0.5",
|
|
40
|
+
"@vaadin/vaadin-themable-mixin": "^21.0.5",
|
|
41
|
+
"@vaadin/vaadin-virtual-list": "^21.0.5"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@esm-bundle/chai": "^4.1.5",
|
|
45
45
|
"@vaadin/testing-helpers": "^0.2.1",
|
|
46
|
-
"@vaadin/vaadin-template-renderer": "^21.0.
|
|
46
|
+
"@vaadin/vaadin-template-renderer": "^21.0.5",
|
|
47
47
|
"lit": "^2.0.0",
|
|
48
48
|
"sinon": "^9.2.0"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "c79135f420e560fa566afc1377db9585757bc4c3"
|
|
54
54
|
}
|
package/src/vaadin-grid.js
CHANGED
|
@@ -317,7 +317,7 @@ class GridElement extends ElementMixin(
|
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
static get version() {
|
|
320
|
-
return '21.0.
|
|
320
|
+
return '21.0.5';
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
static get observers() {
|
|
@@ -540,42 +540,72 @@ class GridElement extends ElementMixin(
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
|
|
543
|
+
/** @private */
|
|
544
|
+
__getIntrinsicWidth(col) {
|
|
545
|
+
const initialWidth = col.width;
|
|
546
|
+
const initialFlexGrow = col.flexGrow;
|
|
547
|
+
|
|
548
|
+
col.width = 'auto';
|
|
549
|
+
col.flexGrow = 0;
|
|
550
|
+
|
|
551
|
+
// Note: _allCells only contains cells which are currently rendered in DOM
|
|
552
|
+
const width = col._allCells
|
|
553
|
+
.filter((cell) => {
|
|
554
|
+
// Exclude body cells that are out of the visible viewport
|
|
555
|
+
return !this.$.items.contains(cell) || this._isInViewport(cell.parentElement);
|
|
556
|
+
})
|
|
557
|
+
.reduce((width, cell) => {
|
|
558
|
+
// Add 1px buffer to the offset width to avoid too narrow columns (sub-pixel rendering)
|
|
559
|
+
return Math.max(width, cell.offsetWidth + 1);
|
|
560
|
+
}, 0);
|
|
561
|
+
|
|
562
|
+
col.flexGrow = initialFlexGrow;
|
|
563
|
+
col.width = initialWidth;
|
|
564
|
+
|
|
565
|
+
return width;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/** @private */
|
|
569
|
+
__getDistributedWidth(col, innerColumn) {
|
|
570
|
+
if (col == null || col === this) return 0;
|
|
571
|
+
|
|
572
|
+
const columnWidth = Math.max(this.__getIntrinsicWidth(col), this.__getDistributedWidth(col.parentElement, col));
|
|
573
|
+
|
|
574
|
+
// we're processing a regular grid-column and not a grid-column-group
|
|
575
|
+
if (!innerColumn) {
|
|
576
|
+
return columnWidth;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// At the end, the width of each vaadin-grid-column-group is determined by the sum of the width of its children.
|
|
580
|
+
// Here we determine how much space the vaadin-grid-column-group actually needs to render properly and then we distribute that space
|
|
581
|
+
// to its children, so when we actually do the summation it will be rendered properly.
|
|
582
|
+
// Check out vaadin-grid-column-group:_updateFlexAndWidth
|
|
583
|
+
const columnGroup = col;
|
|
584
|
+
const columnGroupWidth = columnWidth;
|
|
585
|
+
const sumOfWidthOfAllChildColumns = columnGroup._visibleChildColumns
|
|
586
|
+
.map((col) => this.__getIntrinsicWidth(col))
|
|
587
|
+
.reduce((sum, curr) => sum + curr, 0);
|
|
588
|
+
|
|
589
|
+
const extraNecessarySpaceForGridColumnGroup = Math.max(0, columnGroupWidth - sumOfWidthOfAllChildColumns);
|
|
590
|
+
|
|
591
|
+
// The distribution of the extra necessary space is done according to the intrinsic width of each child column.
|
|
592
|
+
// Lets say we need 100 pixels of extra space for the grid-column-group to render properly
|
|
593
|
+
// it has two grid-column children, |100px|300px| in total 400px
|
|
594
|
+
// the first column gets 25px of the additional space (100/400)*100 = 25
|
|
595
|
+
// the second column gets the 75px of the additional space (300/400)*100 = 75
|
|
596
|
+
const proportionOfExtraSpace = this.__getIntrinsicWidth(innerColumn) / sumOfWidthOfAllChildColumns;
|
|
597
|
+
const shareOfInnerColumnFromNecessaryExtraSpace = proportionOfExtraSpace * extraNecessarySpaceForGridColumnGroup;
|
|
598
|
+
|
|
599
|
+
return this.__getIntrinsicWidth(innerColumn) + shareOfInnerColumnFromNecessaryExtraSpace;
|
|
600
|
+
}
|
|
601
|
+
|
|
543
602
|
/**
|
|
544
603
|
* @param {!Array<!GridColumnElement>} cols the columns to auto size based on their content width
|
|
545
604
|
* @private
|
|
546
605
|
*/
|
|
547
606
|
_recalculateColumnWidths(cols) {
|
|
548
|
-
// Note: The `cols.forEach()` loops below could be implemented as a single loop but this has been
|
|
549
|
-
// split for performance reasons to batch these similar actions [write/read] together to avoid
|
|
550
|
-
// unnecessary layout trashing.
|
|
551
|
-
|
|
552
|
-
// [write] Set automatic width for all cells (breaks column alignment)
|
|
553
|
-
cols.forEach((col) => {
|
|
554
|
-
col.width = 'auto';
|
|
555
|
-
col._origFlexGrow = col.flexGrow;
|
|
556
|
-
col.flexGrow = 0;
|
|
557
|
-
});
|
|
558
|
-
// [read] Measure max cell width in each column
|
|
559
|
-
cols.forEach((col) => {
|
|
560
|
-
col._currentWidth = 0;
|
|
561
|
-
// Note: _allCells only contains cells which are currently rendered in DOM
|
|
562
|
-
col._allCells
|
|
563
|
-
.filter((c) => {
|
|
564
|
-
// Exclude body cells that are out of the visible viewport
|
|
565
|
-
return !this.$.items.contains(c) || this._isInViewport(c.parentElement);
|
|
566
|
-
})
|
|
567
|
-
.forEach((c) => {
|
|
568
|
-
// Add 1px buffer to the offset width to avoid too narrow columns (sub-pixel rendering)
|
|
569
|
-
const cellWidth = c.offsetWidth + 1;
|
|
570
|
-
col._currentWidth = Math.max(col._currentWidth, cellWidth);
|
|
571
|
-
});
|
|
572
|
-
});
|
|
573
|
-
// [write] Set column widths to fit widest measured content
|
|
574
607
|
cols.forEach((col) => {
|
|
575
|
-
col.width = `${col
|
|
576
|
-
col.flexGrow = col._origFlexGrow;
|
|
577
|
-
col._currentWidth = undefined;
|
|
578
|
-
col._origFlexGrow = undefined;
|
|
608
|
+
col.width = `${this.__getDistributedWidth(col)}px`;
|
|
579
609
|
});
|
|
580
610
|
}
|
|
581
611
|
|
|
@@ -864,6 +894,7 @@ class GridElement extends ElementMixin(
|
|
|
864
894
|
this._a11yUpdateHeaderRows();
|
|
865
895
|
this._a11yUpdateFooterRows();
|
|
866
896
|
this.__updateFooterPositioning();
|
|
897
|
+
this.generateCellClassNames();
|
|
867
898
|
}
|
|
868
899
|
|
|
869
900
|
__updateFooterPositioning() {
|