Skip to content

Commit f765c61

Browse files
author
Steven Silvester
authored
Merge pull request #223 from ibdafna/autofit_padd_arg
Add 'padding' argument to fitColumnNames function
2 parents b87ceab + 1d4d145 commit f765c61

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

packages/datagrid/src/datagrid.ts

+15-12
Original file line numberDiff line numberDiff line change
@@ -1481,11 +1481,14 @@ class DataGrid extends Widget {
14811481
this.repaintOverlay();
14821482
}
14831483

1484+
14841485
/**
14851486
* Auto sizes column widths based on their text content.
1486-
* @param area
1487+
* @param area which area to resize: 'body', 'row-header' or 'all'.
1488+
* @param padding padding added to resized columns (pixels).
1489+
* @param numCols specify cap on the number of column resizes (optional).
14871490
*/
1488-
fitColumnNames(area: DataGrid.ColumnFitType = 'all', numCols?: number): void {
1491+
fitColumnNames(area: DataGrid.ColumnFitType = 'all', padding: number = 15, numCols?: number): void {
14891492
// Attempt resizing only if a data model is present.
14901493
if (this.dataModel) {
14911494
// Tracking remaining columns to be resized if numCols arg passed.
@@ -1503,20 +1506,20 @@ class DataGrid extends Widget {
15031506
and set remaining resize allowance number to 0.
15041507
*/
15051508
if (colsRemaining - rowColumnCount < 0) {
1506-
this._fitRowColumnHeaders(this.dataModel, colsRemaining)
1509+
this._fitRowColumnHeaders(this.dataModel, padding, colsRemaining)
15071510
colsRemaining = 0;
15081511
} else {
15091512
/*
15101513
Otherwise the entire row-header column count can be resized.
15111514
Resize all row-header columns and subtract from remaining
15121515
column resize allowance.
15131516
*/
1514-
this._fitRowColumnHeaders(this.dataModel, rowColumnCount);
1517+
this._fitRowColumnHeaders(this.dataModel, padding, rowColumnCount);
15151518
colsRemaining = colsRemaining - rowColumnCount;
15161519
}
15171520
} else {
15181521
// No column resize cap passed - resizing all columns.
1519-
this._fitRowColumnHeaders(this.dataModel);
1522+
this._fitRowColumnHeaders(this.dataModel, padding);
15201523
}
15211524

15221525
}
@@ -1531,20 +1534,20 @@ class DataGrid extends Widget {
15311534
and set remaining resize allowance number to 0.
15321535
*/
15331536
if (colsRemaining - bodyColumnCount < 0) {
1534-
this._fitBodyColumnHeaders(this.dataModel, colsRemaining);
1537+
this._fitBodyColumnHeaders(this.dataModel, padding, colsRemaining);
15351538
colsRemaining = 0;
15361539
} else {
15371540
/*
15381541
Otherwise the entire body column count can be resized.
15391542
Resize based on the smallest number between remaining
15401543
resize allowance and body column count.
15411544
*/
1542-
this._fitBodyColumnHeaders(this.dataModel,
1545+
this._fitBodyColumnHeaders(this.dataModel, padding,
15431546
Math.min(colsRemaining, bodyColumnCount));
15441547
}
15451548
} else {
15461549
// No column resize cap passed - resizing all columns.
1547-
this._fitBodyColumnHeaders(this.dataModel);
1550+
this._fitBodyColumnHeaders(this.dataModel, padding);
15481551
}
15491552
}
15501553
}
@@ -3796,7 +3799,7 @@ class DataGrid extends Widget {
37963799
* without clipping or wrapping.
37973800
* @param dataModel
37983801
*/
3799-
private _fitBodyColumnHeaders(dataModel: DataModel, numCols?: number): void {
3802+
private _fitBodyColumnHeaders(dataModel: DataModel, padding: number, numCols?: number): void {
38003803
// Get the body column count
38013804
const bodyColumnCount = numCols === undefined
38023805
? dataModel.columnCount('body')
@@ -3840,7 +3843,7 @@ class DataGrid extends Widget {
38403843
Send a resize message with new width for the given column.
38413844
Using a padding of 15 pixels to leave some room.
38423845
*/
3843-
this.resizeColumn('body', i, maxWidth + 15);
3846+
this.resizeColumn('body', i, maxWidth + padding);
38443847
}
38453848
}
38463849

@@ -3849,7 +3852,7 @@ class DataGrid extends Widget {
38493852
* without clipping or wrapping.
38503853
* @param dataModel
38513854
*/
3852-
private _fitRowColumnHeaders(dataModel: DataModel, numCols?: number): void {
3855+
private _fitRowColumnHeaders(dataModel: DataModel, padding: number, numCols?: number): void {
38533856
/*
38543857
if we're working with nested row headers,
38553858
retrieve the nested levels and iterate on them.
@@ -3889,7 +3892,7 @@ class DataGrid extends Widget {
38893892
Send a resize message with new width for the given column.
38903893
Using a padding of 15 pixels to leave some room.
38913894
*/
3892-
this.resizeColumn('row-header', i, maxWidth + 15);
3895+
this.resizeColumn('row-header', i, maxWidth + padding);
38933896
}
38943897
}
38953898

0 commit comments

Comments
 (0)