Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for hidden column issue fixes #981 #985

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions src/slick.grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,8 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e

for (let i = 0; i < this.columns.length; i++) {
const m: C = this.columns[i];
if (m.hidden) { continue; }

const headerTarget = this.hasFrozenColumns() ? ((i <= this._options.frozenColumn!) ? this._headerL : this._headerR) : this._headerL;
const headerRowTarget = this.hasFrozenColumns() ? ((i <= this._options.frozenColumn!) ? this._headerRowL : this._headerRowR) : this._headerRowL;

Expand Down Expand Up @@ -1909,16 +1911,17 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
let frozenLeftColMaxWidth = 0;

const children: HTMLElement[] = this.getHeaderChildren();
const vc = this.getVisibleColumns();
for (let i = 0; i < children.length; i++) {
const child = children[i];
const handles = child.querySelectorAll('.slick-resizable-handle');
handles.forEach((handle) => handle.remove());

if (i >= this.columns.length || !this.columns[i] || this.columns[i].hidden) {
if (i >= vc.length || !vc[i]) {
continue;
}

if (this.columns[i].resizable) {
if (vc[i].resizable) {
if (firstResizable === undefined) {
firstResizable = i;
}
Expand All @@ -1933,7 +1936,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
for (let i = 0; i < children.length; i++) {
const colElm = children[i];

if (i >= this.columns.length || !this.columns[i] || this.columns[i].hidden) {
if (i >= vc.length || !vc[i]) {
continue;
}
if (i < firstResizable || (this._options.forceFitColumns && i >= lastResizable)) {
Expand All @@ -1959,18 +1962,18 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
let stretchLeewayOnRight: number | null = null;
// lock each column's width option to current width
for (let pw = 0; pw < children.length; pw++) {
if (pw >= this.columns.length || !this.columns[pw] || this.columns[pw].hidden) {
if (pw >= vc.length || !vc[pw]) {
continue;
}
this.columns[pw].previousWidth = children[pw].offsetWidth;
vc[pw].previousWidth = children[pw].offsetWidth;
}
if (this._options.forceFitColumns) {
shrinkLeewayOnRight = 0;
stretchLeewayOnRight = 0;
// colums on right affect maxPageX/minPageX
for (j = i + 1; j < this.columns.length; j++) {
c = this.columns[j];
if (c && c.resizable && !c.hidden) {
for (j = i + 1; j < vc.length; j++) {
c = vc[j];
if (c && c.resizable) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use optional chaining here ?. you can see more info on MDN optional chaining

if (stretchLeewayOnRight !== null) {
if (c.maxWidth) {
stretchLeewayOnRight += c.maxWidth - (c.previousWidth || 0);
Expand All @@ -1986,8 +1989,8 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
let stretchLeewayOnLeft: number | null = 0;
for (j = 0; j <= i; j++) {
// columns on left only affect minPageX
c = this.columns[j];
if (c && c.resizable && !c.hidden) {
c = vc[j];
if (c && c.resizable) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use optional chaining here too ?.

if (stretchLeewayOnLeft !== null) {
if (c.maxWidth) {
stretchLeewayOnLeft += c.maxWidth - (c.previousWidth || 0);
Expand Down Expand Up @@ -2027,7 +2030,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
x = d;

for (j = i; j >= 0; j--) {
c = this.columns[j];
c = vc[j];
if (c && c.resizable && !c.hidden) {
actualMinWidth = Math.max(c.minWidth || 0, this.absoluteColumnMinWidth);
if (x && (c.previousWidth || 0) + x < actualMinWidth) {
Expand All @@ -2041,7 +2044,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
}

for (k = 0; k <= i; k++) {
c = this.columns[k];
c = vc[k];
if (!c || c.hidden) { continue; }

if (this.hasFrozenColumns() && (k > this._options.frozenColumn!)) {
Expand All @@ -2053,8 +2056,8 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e

if (this._options.forceFitColumns) {
x = -d;
for (j = i + 1; j < this.columns.length; j++) {
c = this.columns[j];
for (j = i + 1; j < vc.length; j++) {
c = vc[j];
if (!c || c.hidden) { continue; }
if (c.resizable) {
if (x && c.maxWidth && (c.maxWidth - (c.previousWidth || 0) < x)) {
Expand All @@ -2073,8 +2076,8 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
}
}
} else {
for (j = i + 1; j < this.columns.length; j++) {
c = this.columns[j];
for (j = i + 1; j < vc.length; j++) {
c = vc[j];
if (!c || c.hidden) { continue; }

if (this.hasFrozenColumns() && (j > this._options.frozenColumn!)) {
Expand All @@ -2087,8 +2090,8 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e

if (this._options.forceFitColumns) {
x = -d;
for (j = i + 1; j < this.columns.length; j++) {
c = this.columns[j];
for (j = i + 1; j < vc.length; j++) {
c = vc[j];
if (!c || c.hidden) { continue; }
if (c.resizable) {
if (x && c.maxWidth && (c.maxWidth - (c.previousWidth || 0) < x)) {
Expand All @@ -2108,7 +2111,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
newCanvasWidthR = 0;

for (j = i; j >= 0; j--) {
c = this.columns[j];
c = vc[j];
if (!c || c.hidden) { continue; }
if (c.resizable) {
if (x && c.maxWidth && (c.maxWidth - (c.previousWidth || 0) < x)) {
Expand All @@ -2133,7 +2136,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
}

for (k = 0; k <= i; k++) {
c = this.columns[k];
c = vc[k];
if (!c || c.hidden) { continue; }

if (this.hasFrozenColumns() && (k > this._options.frozenColumn!)) {
Expand All @@ -2145,8 +2148,8 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e

if (this._options.forceFitColumns) {
x = -d;
for (j = i + 1; j < this.columns.length; j++) {
c = this.columns[j];
for (j = i + 1; j < vc.length; j++) {
c = vc[j];
if (!c || c.hidden) { continue; }
if (c.resizable) {
actualMinWidth = Math.max(c.minWidth || 0, this.absoluteColumnMinWidth);
Expand All @@ -2166,8 +2169,8 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
}
}
} else {
for (j = i + 1; j < this.columns.length; j++) {
c = this.columns[j];
for (j = i + 1; j < vc.length; j++) {
c = vc[j];
if (!c || c.hidden) { continue; }

if (this.hasFrozenColumns() && (j > this._options.frozenColumn!)) {
Expand Down Expand Up @@ -2202,8 +2205,8 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
this.applyColumnHeaderWidths();
}
let newWidth;
for (j = 0; j < this.columns.length; j++) {
c = this.columns[j];
for (j = 0; j < vc.length; j++) {
c = vc[j];
if (!c || c.hidden) { continue; }
newWidth = children[j].offsetWidth;

Expand Down
Loading