@@ -469,13 +469,48 @@ export class DataGridView extends DOMWidgetView {
469469 this . grid . editable = this . model . get ( 'editable' ) ;
470470 } ) ;
471471
472+ this . model . on_some_change (
473+ [ 'auto_fit_columns' , 'auto_fit_params' ] ,
474+ ( ) => {
475+ this . handleColumnAutoFit ( ) ;
476+ } ,
477+ this ,
478+ ) ;
479+
480+ if ( this . model . get ( 'auto_fit_columns' ) ) {
481+ this . handleColumnAutoFit ( ) ;
482+ }
483+
472484 return this . updateRenderers ( ) . then ( ( ) => {
473485 this . updateGridStyle ( ) ;
474486 this . updateGridRenderers ( ) ;
475487 this . pWidget . addWidget ( this . grid ) ;
476488 } ) ;
477489 }
478490
491+ private handleColumnAutoFit ( ) {
492+ // Check whether we need to auto-fit or revert to base size.
493+ const shouldAutoFit = this . model . get ( 'auto_fit_columns' ) ;
494+ if ( ! shouldAutoFit ) {
495+ this . grid . baseColumnSize = this . model . get ( 'base_column_size' ) ;
496+ // Terminate call here if not auto-fitting.
497+ return ;
498+ }
499+
500+ // Retrieve user-defined auto-fit params
501+ let { area, padding, numCols } = this . model . get ( 'auto_fit_params' ) ;
502+
503+ // Data validation on params
504+ area = area ?? 'all' ;
505+ padding = padding ?? 30 ;
506+ numCols = numCols ?? undefined ;
507+ console . log ( area , padding , numCols ) ;
508+
509+ // Call resize function
510+ //@ts -ignore
511+ this . grid . grid . fitColumnNames ( area , padding , numCols ) ;
512+ }
513+
479514 private updateRenderers ( ) {
480515 // Unlisten to previous renderers
481516 if ( this . default_renderer ) {
0 commit comments