@@ -13,6 +13,35 @@ export const GridHelper = declare(null, {
1313 postCreate : function postCreate ( inherited ) {
1414 this . inherited ( postCreate , arguments ) ;
1515
16+ // Emit dgrid-column-autofit on double-mousedown over a resize handle.
17+ // A native dblclick is never fired because dgrid calls e.preventDefault()
18+ // on every mousedown on .dgrid-resize-handle.
19+ // We use a capture-phase listener on headerNode so we fire BEFORE dgrid's
20+ // bubble-phase delegated handler, allowing us to stopPropagation on the
21+ // second click to prevent dgrid from starting a resize drag.
22+ const self = this ;
23+ let _lastResizeDownTime = 0 ;
24+ let _lastResizeColId : string | null = null ;
25+ this . headerNode . addEventListener ( "mousedown" , function ( evt : MouseEvent ) {
26+ const target = evt . target as any ;
27+ if ( ! target . classList . contains ( "dgrid-resize-handle" ) ) return ;
28+ const colId : string = target . columnId ;
29+ const now = Date . now ( ) ;
30+ const delta = now - _lastResizeDownTime ;
31+ if ( colId === _lastResizeColId && delta <= 300 ) {
32+ _lastResizeDownTime = 0 ;
33+ _lastResizeColId = null ;
34+ evt . stopPropagation ( ) ;
35+ evt . preventDefault ( ) ;
36+ const detail = self . columns [ colId ] ;
37+ if ( ! detail ) return ;
38+ self . domNode . dispatchEvent ( new CustomEvent ( "dgrid-column-autofit" , { detail, bubbles : true , cancelable : true } ) ) ;
39+ } else {
40+ _lastResizeDownTime = now ;
41+ _lastResizeColId = colId ;
42+ }
43+ } , { capture : true } ) ;
44+
1645 this . __hpcc_tooltip_header = new Tooltip ( {
1746 connectId : [ this . id ] ,
1847 selector : ".dgrid-resize-header-container" ,
@@ -53,6 +82,26 @@ export const GridHelper = declare(null, {
5382 node . checked = false ;
5483 node . indeterminate = false ;
5584 } ) ;
85+ } ,
86+
87+ applyWidth : function ( id : string , cssWidth : string ) {
88+ const existingRule = this . _columnSizes ?. [ id ] ;
89+ if ( existingRule ?. set ) {
90+ existingRule . set ( "width" , cssWidth ) ;
91+ } else {
92+ this . styleColumn ( id , `width: ${ cssWidth } ` ) ;
93+ }
94+ } ,
95+
96+ resizeColumn : function resizeColumn ( colId : string , widthPx : number ) {
97+ this . applyWidth ( colId , `${ widthPx } px` ) ;
98+
99+ // Reset the last visible column to auto so it fills remaining space.
100+ const lastColId : string | undefined = this . _getResizedColumnWidths ?.( ) ?. lastColId ;
101+ if ( lastColId && lastColId !== colId ) {
102+ this . applyWidth ( lastColId , "auto" ) ;
103+ }
104+ this . resize ( ) ;
56105 } /*,
57106
58107 _onNotify(object, existingId) {
0 commit comments