@@ -1481,11 +1481,14 @@ class DataGrid extends Widget {
1481
1481
this . repaintOverlay ( ) ;
1482
1482
}
1483
1483
1484
+
1484
1485
/**
1485
1486
* 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).
1487
1490
*/
1488
- fitColumnNames ( area : DataGrid . ColumnFitType = 'all' , numCols ?: number ) : void {
1491
+ fitColumnNames ( area : DataGrid . ColumnFitType = 'all' , padding : number = 15 , numCols ?: number ) : void {
1489
1492
// Attempt resizing only if a data model is present.
1490
1493
if ( this . dataModel ) {
1491
1494
// Tracking remaining columns to be resized if numCols arg passed.
@@ -1503,20 +1506,20 @@ class DataGrid extends Widget {
1503
1506
and set remaining resize allowance number to 0.
1504
1507
*/
1505
1508
if ( colsRemaining - rowColumnCount < 0 ) {
1506
- this . _fitRowColumnHeaders ( this . dataModel , colsRemaining )
1509
+ this . _fitRowColumnHeaders ( this . dataModel , colsRemaining , padding )
1507
1510
colsRemaining = 0 ;
1508
1511
} else {
1509
1512
/*
1510
1513
Otherwise the entire row-header column count can be resized.
1511
1514
Resize all row-header columns and subtract from remaining
1512
1515
column resize allowance.
1513
1516
*/
1514
- this . _fitRowColumnHeaders ( this . dataModel , rowColumnCount ) ;
1517
+ this . _fitRowColumnHeaders ( this . dataModel , rowColumnCount , padding ) ;
1515
1518
colsRemaining = colsRemaining - rowColumnCount ;
1516
1519
}
1517
1520
} else {
1518
1521
// No column resize cap passed - resizing all columns.
1519
- this . _fitRowColumnHeaders ( this . dataModel ) ;
1522
+ this . _fitRowColumnHeaders ( this . dataModel , padding ) ;
1520
1523
}
1521
1524
1522
1525
}
@@ -1531,7 +1534,7 @@ class DataGrid extends Widget {
1531
1534
and set remaining resize allowance number to 0.
1532
1535
*/
1533
1536
if ( colsRemaining - bodyColumnCount < 0 ) {
1534
- this . _fitBodyColumnHeaders ( this . dataModel , colsRemaining ) ;
1537
+ this . _fitBodyColumnHeaders ( this . dataModel , colsRemaining , padding ) ;
1535
1538
colsRemaining = 0 ;
1536
1539
} else {
1537
1540
/*
@@ -1540,11 +1543,11 @@ class DataGrid extends Widget {
1540
1543
resize allowance and body column count.
1541
1544
*/
1542
1545
this . _fitBodyColumnHeaders ( this . dataModel ,
1543
- Math . min ( colsRemaining , bodyColumnCount ) ) ;
1546
+ Math . min ( colsRemaining , bodyColumnCount ) , padding ) ;
1544
1547
}
1545
1548
} else {
1546
1549
// No column resize cap passed - resizing all columns.
1547
- this . _fitBodyColumnHeaders ( this . dataModel ) ;
1550
+ this . _fitBodyColumnHeaders ( this . dataModel , padding ) ;
1548
1551
}
1549
1552
}
1550
1553
}
@@ -3796,7 +3799,7 @@ class DataGrid extends Widget {
3796
3799
* without clipping or wrapping.
3797
3800
* @param dataModel
3798
3801
*/
3799
- private _fitBodyColumnHeaders ( dataModel : DataModel , numCols ?: number ) : void {
3802
+ private _fitBodyColumnHeaders ( dataModel : DataModel , padding : number , numCols ?: number ) : void {
3800
3803
// Get the body column count
3801
3804
const bodyColumnCount = numCols === undefined
3802
3805
? dataModel . columnCount ( 'body' )
@@ -3840,7 +3843,7 @@ class DataGrid extends Widget {
3840
3843
Send a resize message with new width for the given column.
3841
3844
Using a padding of 15 pixels to leave some room.
3842
3845
*/
3843
- this . resizeColumn ( 'body' , i , maxWidth + 15 ) ;
3846
+ this . resizeColumn ( 'body' , i , maxWidth + padding ) ;
3844
3847
}
3845
3848
}
3846
3849
@@ -3849,7 +3852,7 @@ class DataGrid extends Widget {
3849
3852
* without clipping or wrapping.
3850
3853
* @param dataModel
3851
3854
*/
3852
- private _fitRowColumnHeaders ( dataModel : DataModel , numCols ?: number ) : void {
3855
+ private _fitRowColumnHeaders ( dataModel : DataModel , padding : number , numCols ?: number ) : void {
3853
3856
/*
3854
3857
if we're working with nested row headers,
3855
3858
retrieve the nested levels and iterate on them.
@@ -3889,7 +3892,7 @@ class DataGrid extends Widget {
3889
3892
Send a resize message with new width for the given column.
3890
3893
Using a padding of 15 pixels to leave some room.
3891
3894
*/
3892
- this . resizeColumn ( 'row-header' , i , maxWidth + 15 ) ;
3895
+ this . resizeColumn ( 'row-header' , i , maxWidth + padding ) ;
3893
3896
}
3894
3897
}
3895
3898
0 commit comments