@churchillliving/se-ui-toolkit 6.56.19 → 6.56.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10978,39 +10978,90 @@ class GridComponent {
10978
10978
  }
10979
10979
  this.saveColumnWidths();
10980
10980
  }
10981
+ onColumnHeaderDblClick(event, columnHeader, dt) {
10982
+ event.preventDefault();
10983
+ event.stopPropagation();
10984
+ console.log('Double click detected - auto-fitting all columns');
10985
+ // Auto-fit all columns instead of just the one clicked
10986
+ this.selectedColumns.forEach((column) => {
10987
+ this.autoFitColumnWidth(column.header, dt);
10988
+ });
10989
+ }
10981
10990
  autoFitColumnWidth(columnHeader, dt) {
10982
- if (!dt?.el?.nativeElement?.id)
10983
- return;
10984
- this.gridId = dt.el.nativeElement.id;
10985
- const columnIndex = this.selectedColumns.findIndex((col) => col.header?.toLowerCase() === columnHeader?.toLowerCase());
10986
- if (columnIndex < 0)
10991
+ if (!columnHeader || !dt?.el?.nativeElement) {
10992
+ console.log('Missing columnHeader or dt');
10987
10993
  return;
10988
- const column = this.selectedColumns[columnIndex];
10994
+ }
10989
10995
  const table = dt.el.nativeElement;
10990
- const cells = table.querySelectorAll(`td:nth-child(${columnIndex + 1}), th:nth-child(${columnIndex + 1})`);
10991
- let maxWidth = 50;
10992
- cells.forEach((cell) => {
10993
- const scrollWidth = cell.scrollWidth;
10994
- if (scrollWidth > maxWidth) {
10995
- maxWidth = scrollWidth;
10996
+ const headerCell = table.querySelector(`th[id="${columnHeader}"]`);
10997
+ if (!headerCell) {
10998
+ console.log('Header cell not found for:', columnHeader);
10999
+ return;
11000
+ }
11001
+ const headerRow = headerCell.parentElement;
11002
+ if (!headerRow) {
11003
+ console.log('Header row not found');
11004
+ return;
11005
+ }
11006
+ const cellIndex = Array.from(headerRow.children).indexOf(headerCell);
11007
+ if (cellIndex < 0) {
11008
+ console.log('Cell index not found');
11009
+ return;
11010
+ }
11011
+ const tbody = table.querySelector('tbody');
11012
+ if (!tbody) {
11013
+ console.log('tbody not found');
11014
+ return;
11015
+ }
11016
+ const rows = tbody.querySelectorAll('tr');
11017
+ let maxWidth = headerCell.scrollWidth;
11018
+ console.log('Header cell scrollWidth:', maxWidth);
11019
+ rows.forEach((row) => {
11020
+ const cell = row.children[cellIndex];
11021
+ if (cell) {
11022
+ const scrollWidth = cell.scrollWidth;
11023
+ console.log('Cell scrollWidth:', scrollWidth);
11024
+ if (scrollWidth > maxWidth) {
11025
+ maxWidth = scrollWidth;
11026
+ }
10996
11027
  }
10997
11028
  });
10998
- const padding = 8;
10999
- const calculatedWidth = maxWidth + padding;
11000
- column['customWidth'] = calculatedWidth;
11001
- this.saveColumnWidths();
11002
- }
11003
- onColumnHeaderDblClick(event, columnHeader, dt) {
11004
- const target = event.target;
11005
- const th = target.closest('th');
11006
- if (!th)
11007
- return;
11008
- const rect = th.getBoundingClientRect();
11009
- const threshold = 10;
11010
- const distanceFromRight = rect.right - event.clientX;
11011
- if (distanceFromRight <= threshold) {
11012
- event.preventDefault();
11013
- this.autoFitColumnWidth(columnHeader, dt);
11029
+ const column = this.selectedColumns.find((col) => col.header?.toLowerCase() === columnHeader?.toLowerCase());
11030
+ if (column) {
11031
+ const padding = 12;
11032
+ const newWidth = Math.ceil(maxWidth + padding);
11033
+ console.log('Setting column width to:', newWidth);
11034
+ // Remove width constraints from CSS for this column
11035
+ const styleSheets = document.styleSheets;
11036
+ for (let i = 0; i < styleSheets.length; i++) {
11037
+ try {
11038
+ const rules = styleSheets[i].cssRules;
11039
+ for (let j = rules.length - 1; j >= 0; j--) {
11040
+ const rule = rules[j];
11041
+ if (rule.selectorText && rule.selectorText.includes(`nth-child(${cellIndex + 1})`) &&
11042
+ rule.selectorText.includes('GridComponentTable')) {
11043
+ console.log('Removing CSS rule:', rule.selectorText);
11044
+ styleSheets[i].deleteRule(j);
11045
+ }
11046
+ }
11047
+ }
11048
+ catch (e) {
11049
+ // CORS errors on external stylesheets, ignore
11050
+ }
11051
+ }
11052
+ column['customWidth'] = newWidth;
11053
+ column['columnWidth'] = newWidth;
11054
+ // Update through data binding
11055
+ this.selectedColumns = [...this.selectedColumns];
11056
+ this.saveColumnWidths();
11057
+ // Force table recalculation
11058
+ this.cdr.detectChanges();
11059
+ setTimeout(() => {
11060
+ this.cdr.detectChanges();
11061
+ }, 50);
11062
+ }
11063
+ else {
11064
+ console.log('Column not found in selectedColumns');
11014
11065
  }
11015
11066
  }
11016
11067
  saveColumnWidths(toggleColumns = []) {