@@ -151,11 +151,19 @@ class FeatherGridMouseHandler extends BasicMouseHandler {
151151
152152export
153153class FeatherGrid extends Widget {
154- constructor ( ) {
154+ constructor ( options : DataGrid . IOptions = { } ) {
155155 super ( ) ;
156156 this . addClass ( 'ipydatagrid-widget' ) ;
157157
158- this . _createGrid ( ) ;
158+ if ( options . defaultSizes ) {
159+ this . _baseRowSize = options . defaultSizes . rowHeight || this . _baseRowSize ;
160+ this . _baseColumnSize = options . defaultSizes . columnWidth || this . _baseColumnSize ;
161+ this . _baseRowHeaderSize = options . defaultSizes . rowHeaderWidth || this . _baseRowHeaderSize ;
162+ this . _baseColumnHeaderSize = options . defaultSizes . columnHeaderHeight || this . _baseColumnHeaderSize ;
163+ }
164+ this . _headerVisibility = options . headerVisibility || this . _headerVisibility ;
165+
166+ this . _createGrid ( options ) ;
159167
160168 this . _defaultRenderer = new TextRenderer ( {
161169 font : '12px sans-serif' ,
@@ -235,6 +243,7 @@ class FeatherGrid extends Widget {
235243 }
236244
237245 this . grid . defaultSizes = { ...this . grid . defaultSizes , columnWidth : size } ;
246+ this . _updateColumnWidths ( ) ;
238247 }
239248
240249 get baseColumnSize ( ) : number {
@@ -263,6 +272,7 @@ class FeatherGrid extends Widget {
263272 }
264273
265274 this . grid . defaultSizes = { ...this . grid . defaultSizes , rowHeaderWidth : size } ;
275+ this . _updateColumnWidths ( ) ;
266276 }
267277
268278 get baseRowHeaderSize ( ) : number {
@@ -291,6 +301,7 @@ class FeatherGrid extends Widget {
291301 }
292302
293303 this . grid . headerVisibility = visibility ;
304+ this . _updateColumnWidths ( ) ;
294305 }
295306
296307 get headerVisibility ( ) : DataGrid . HeaderVisibility {
@@ -354,15 +365,17 @@ class FeatherGrid extends Widget {
354365 return this . grid . cellRenderers ;
355366 }
356367
357- private _createGrid ( ) {
368+ private _createGrid ( options : DataGrid . IOptions = { } ) {
358369 this . grid = new DataGrid ( {
359- defaultSizes : {
360- rowHeight : this . _baseRowSize ,
361- columnWidth : this . _baseColumnSize ,
362- rowHeaderWidth : this . _baseRowHeaderSize ,
363- columnHeaderHeight : this . _baseColumnHeaderSize
364- } ,
365- headerVisibility : this . _headerVisibility
370+ ...options , ...{
371+ defaultSizes : {
372+ rowHeight : this . _baseRowSize ,
373+ columnWidth : this . _baseColumnSize ,
374+ rowHeaderWidth : this . _baseRowHeaderSize ,
375+ columnHeaderHeight : this . _baseColumnHeaderSize
376+ } ,
377+ headerVisibility : this . _headerVisibility
378+ }
366379 } ) ;
367380
368381 MessageLoop . installMessageHook ( this . grid . viewport , this ) ;
@@ -688,44 +701,40 @@ class FeatherGrid extends Widget {
688701 private _updateGridRenderers ( ) {
689702 this . grid . cellRenderers . update ( { 'body' : this . _rendererResolver . bind ( this ) } ) ;
690703 }
691-
692- /**
693- * This function resets the column sizes to the base column size and functions
694- * identically to phosphor's resetColumns() but does not call _repaintOverlay
695- * or _repaintContent in the process.
696- */
697- private _resetAllColumnWidths ( ) {
698- let column_base_size = this . _baseColumnSize ;
699-
700- // Resizing columns from body region
701- for ( let i = 0 ; i < this . grid . columnCount ( 'body' ) ; i ++ ) {
702- this . grid . resizeColumn ( 'body' , i , column_base_size )
703- }
704-
705- // Resizing columns from row header region
706- for ( let i = 0 ; i < this . grid . columnCount ( 'column-header' ) ; i ++ ) {
707- this . grid . resizeColumn ( 'row-header' , i , column_base_size )
708- }
709- }
710-
704+
711705 private _updateColumnWidths ( ) {
712- //@ts -ignore added so we don't have to add basicmousehandler.ts fork
706+ const columnWidths = this . _columnWidths ;
707+ // @ts -ignore added so we don't have to add basicmousehandler.ts fork
713708 let mouseHandler = this . grid . mouseHandler as FeatherGridMouseHandler ;
714-
709+
715710 // Do not want this callback to be executed when user resizes using the mouse
716- if ( ! mouseHandler . mouseIsDown ) {
717- let column_widths_dict = this . _columnWidths ;
718-
719- this . _resetAllColumnWidths ( ) ;
720-
721- for ( let key in column_widths_dict ) {
722- let index = this . dataModel . columnNameToIndex ( key ) ;
723- let region = this . dataModel . columnNameToRegion ( key ) ;
724- this . grid . resizeColumn ( region , index , column_widths_dict [ key ] ) ;
711+ if ( mouseHandler . mouseIsDown ) {
712+ return ;
713+ }
714+
715+ // Resizing columns from row header region
716+ if ( this . _headerVisibility === 'row' || this . _headerVisibility === 'all' ) {
717+ const baseRowHeaderSize = this . _baseRowHeaderSize ;
718+ const rowHeaderColCount = this . grid . columnCount ( 'row-header' ) ;
719+ for ( let i = 0 ; i < rowHeaderColCount ; i ++ ) {
720+ const colName = this . dataModel . columnIndexToName ( i , 'row-header' ) ;
721+ const colSize = columnWidths . hasOwnProperty ( colName ) ? columnWidths [ colName ] : baseRowHeaderSize ;
722+
723+ this . grid . resizeColumn ( 'row-header' , i , colSize ) ;
725724 }
726725 }
726+
727+ // Resizing columns from body region
728+ const baseColumnSize = this . _baseColumnSize ;
729+ const bodyColCount = this . grid . columnCount ( 'body' ) ;
730+ for ( let i = 0 ; i < bodyColCount ; i ++ ) {
731+ const colName = this . dataModel . columnIndexToName ( i , 'body' ) ;
732+ const colSize = columnWidths . hasOwnProperty ( colName ) ? columnWidths [ colName ] : baseColumnSize ;
733+
734+ this . grid . resizeColumn ( 'body' , i , colSize ) ;
735+ }
727736 }
728-
737+
729738 private _updateHeaderRenderer ( ) {
730739 const headerRenderer = new HeaderRenderer ( {
731740 textOptions : {
0 commit comments