Skip to content

Commit 929658f

Browse files
authored
Fix previous data remaining when updating max-width. (#367)
1 parent a144465 commit 929658f

File tree

6 files changed

+50
-13
lines changed

6 files changed

+50
-13
lines changed

packages/cheetah-grid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cheetah-grid",
3-
"version": "1.7.1",
3+
"version": "1.7.2",
44
"description": "Cheetah Grid is a high performance grid engine that works on canvas",
55
"keywords": [
66
"spreadsheet",

packages/cheetah-grid/src/js/ListGrid.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,18 @@ function _refreshHeader<T>(grid: ListGrid<T>): void {
486486
const { width, minWidth, maxWidth } = column;
487487
if (width && (width > 0 || typeof width === "string")) {
488488
grid.setColWidth(col, width);
489+
} else {
490+
grid.setColWidth(col, null);
489491
}
490492
if (minWidth && (minWidth > 0 || typeof minWidth === "string")) {
491493
grid.setMinColWidth(col, minWidth);
494+
} else {
495+
grid.setMinColWidth(col, null);
492496
}
493497
if (maxWidth && (maxWidth > 0 || typeof maxWidth === "string")) {
494498
grid.setMaxColWidth(col, maxWidth);
499+
} else {
500+
grid.setMaxColWidth(col, null);
495501
}
496502
}
497503
const { headerRowHeight } = grid[_];
@@ -501,6 +507,8 @@ function _refreshHeader<T>(grid: ListGrid<T>): void {
501507
: headerRowHeight;
502508
if (height && height > 0) {
503509
grid.setRowHeight(row, height);
510+
} else {
511+
grid.setRowHeight(row, null);
504512
}
505513
}
506514
grid.colCount = layoutMap.colCount;

packages/cheetah-grid/src/js/core/DrawGrid.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,13 @@ function _getColWidth(grid: DrawGrid, col: number): number {
793793
function _setColWidth(
794794
grid: DrawGrid,
795795
col: number,
796-
width: string | number
796+
width: string | number | null
797797
): void {
798-
grid[_].colWidthsMap.put(col, width);
798+
if (width != null) {
799+
grid[_].colWidthsMap.put(col, width);
800+
} else {
801+
grid[_].colWidthsMap.remove(col);
802+
}
799803
}
800804

801805
/**
@@ -859,8 +863,16 @@ function _getRowHeight(this: DrawGrid, row: number): number {
859863
return this[_].defaultRowHeight;
860864
}
861865
/** @private */
862-
function _setRowHeight(grid: DrawGrid, row: number, height: number): void {
863-
grid[_].rowHeightsMap.put(row, height);
866+
function _setRowHeight(
867+
grid: DrawGrid,
868+
row: number,
869+
height: number | null
870+
): void {
871+
if (height != null) {
872+
grid[_].rowHeightsMap.put(row, height);
873+
} else {
874+
grid[_].rowHeightsMap.remove(row);
875+
}
864876
}
865877
/** @private */
866878
function _getRowsHeight(
@@ -3217,7 +3229,7 @@ export abstract class DrawGrid extends EventTarget implements DrawGridAPI {
32173229
* @param {number} height The row height
32183230
* @return {void}
32193231
*/
3220-
setRowHeight(row: number, height: number): void {
3232+
setRowHeight(row: number, height: number | null): void {
32213233
_setRowHeight(this, row, height);
32223234
}
32233235
/**
@@ -3234,7 +3246,7 @@ export abstract class DrawGrid extends EventTarget implements DrawGridAPI {
32343246
* @param {number} width The column width
32353247
* @return {void}
32363248
*/
3237-
setColWidth(col: number, width: string | number): void {
3249+
setColWidth(col: number, width: string | number | null): void {
32383250
_setColWidth(this, col, width);
32393251
}
32403252
/**
@@ -3252,10 +3264,14 @@ export abstract class DrawGrid extends EventTarget implements DrawGridAPI {
32523264
* @param {number} maxwidth The column max width
32533265
* @return {void}
32543266
*/
3255-
setMaxColWidth(col: number, maxwidth: string | number): void {
3267+
setMaxColWidth(col: number, maxwidth: string | number | null): void {
32563268
const obj =
32573269
this[_].colWidthsLimit[col] || (this[_].colWidthsLimit[col] = {});
3258-
obj.max = maxwidth;
3270+
if (maxwidth != null) {
3271+
obj.max = maxwidth;
3272+
} else {
3273+
delete obj.max;
3274+
}
32593275
}
32603276
/**
32613277
* Get the column min width of the given the column index.
@@ -3272,10 +3288,14 @@ export abstract class DrawGrid extends EventTarget implements DrawGridAPI {
32723288
* @param {number} minwidth The column min width
32733289
* @return {void}
32743290
*/
3275-
setMinColWidth(col: number, minwidth: string | number): void {
3291+
setMinColWidth(col: number, minwidth: string | number | null): void {
32763292
const obj =
32773293
this[_].colWidthsLimit[col] || (this[_].colWidthsLimit[col] = {});
3278-
obj.min = minwidth;
3294+
if (minwidth != null) {
3295+
obj.min = minwidth;
3296+
} else {
3297+
delete obj.min;
3298+
}
32793299
}
32803300
/**
32813301
* Get the rect of the cell.

packages/cheetah-grid/src/js/internal/NumberMap.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ export class NumberMap<T> {
2525
}
2626
this._vals[key] = value;
2727
}
28+
remove(key: number): void {
29+
delete this._vals[key];
30+
const index = this._keys.indexOf(key);
31+
if (index < 0) {
32+
return;
33+
}
34+
this._keys.splice(index, 1);
35+
this._sorted = false;
36+
}
2837
get(key: number): T | undefined {
2938
return this._vals[key];
3039
}

packages/cheetah-grid/src/js/ts-types/grid-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export interface DrawGridAPI {
8383
getRowHeight(row: number): number;
8484
setRowHeight(row: number, height: number): void;
8585
getColWidth(col: number): number;
86-
setColWidth(col: number, width: number): void;
86+
setColWidth(col: number, width: string | number | null): void;
8787
getMaxColWidth(col: number): string | number | undefined;
8888
setMaxColWidth(col: number, maxwidth: string | number): void;
8989
getMinColWidth(col: number): string | number | undefined;

packages/vue-cheetah-grid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cheetah-grid",
3-
"version": "1.7.1",
3+
"version": "1.7.2",
44
"description": "Cheetah Grid for Vue.js",
55
"main": "lib/index.js",
66
"unpkg": "dist/vueCheetahGrid.js",

0 commit comments

Comments
 (0)