ms-data-grid 0.0.148 → 0.0.149

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.
@@ -1903,7 +1903,7 @@ class DataGridComponent {
1903
1903
  this.renderStart = 0; // where the slice actually starts (firstIndex - overscan, clamped)
1904
1904
  this.scrollRaf = null;
1905
1905
  this.pendingScrollTop = 0;
1906
- this.overscan = 0; // buffer rows above and below
1906
+ this.overscan = 4; // buffer rows above and below
1907
1907
  this.dragStartIndex = 0;
1908
1908
  // onDragStart(data: any, index: number) {
1909
1909
  // this.draggingColumn = data.column;
@@ -2764,78 +2764,161 @@ class DataGridComponent {
2764
2764
  .reduce((acc, part) => (acc && acc[part] !== undefined ? acc[part] : undefined), obj);
2765
2765
  return Array.isArray(value);
2766
2766
  }
2767
- onResizeGroup(event, col, isRightPinned) {
2767
+ // onResizeGroup(event: MouseEvent, col: any, isRightPinned?: boolean): void {
2768
+ // event.preventDefault();
2769
+ // event.stopPropagation();
2770
+ // const startX = event.clientX;
2771
+ // const children = col.children || [];
2772
+ // if (!children.length) return;
2773
+ // const childWidths: { field: string; width: number }[] = children.map(
2774
+ // (child: any) => {
2775
+ // const el = document.querySelector(
2776
+ // `[field="${child.field}"]`
2777
+ // ) as HTMLElement;
2778
+ // return {
2779
+ // field: child.field,
2780
+ // width: el?.offsetWidth || 0,
2781
+ // };
2782
+ // }
2783
+ // );
2784
+ // const totalInitialWidth = childWidths.reduce(
2785
+ // (sum, col) => sum + col.width,
2786
+ // 0
2787
+ // );
2788
+ // const onMouseMove = (moveEvent: MouseEvent) => {
2789
+ // let deltaX = moveEvent.clientX - startX;
2790
+ // if (isRightPinned) {
2791
+ // deltaX = -deltaX;
2792
+ // }
2793
+ // // Prevent shrinking too small
2794
+ // if (totalInitialWidth + deltaX < children.length * 80) return;
2795
+ // let totalNewWidth = 0;
2796
+ // childWidths.forEach((child) => {
2797
+ // const ratio = child.width / totalInitialWidth;
2798
+ // const newWidth = Math.max(child.width + deltaX * ratio, 80);
2799
+ // totalNewWidth += newWidth;
2800
+ // const childEls = document.querySelectorAll(`[field="${child.field}"]`);
2801
+ // childEls.forEach((el: Element) => {
2802
+ // const elHtml = el as HTMLElement;
2803
+ // elHtml.style.minWidth = `${newWidth}px`;
2804
+ // elHtml.style.width = `${newWidth}px`;
2805
+ // });
2806
+ // this.updateColumnWidthInSourceByField(child.field, newWidth);
2807
+ // });
2808
+ // // ✅ Update group header width in DOM
2809
+ // const groupHeaderEl = document.querySelector(
2810
+ // `[group="${col.header}"]`
2811
+ // ) as HTMLElement;
2812
+ // if (groupHeaderEl) {
2813
+ // groupHeaderEl.style.width = `${totalNewWidth}px`;
2814
+ // }
2815
+ // };
2816
+ // const onMouseUp = () => {
2817
+ // if (this.tableFilterViewId) {
2818
+ // this.savePreset('mouseUp');
2819
+ // }
2820
+ // this.refreshHeaders();
2821
+ // window.removeEventListener('mousemove', onMouseMove);
2822
+ // window.removeEventListener('mouseup', onMouseUp);
2823
+ // const sendData = {
2824
+ // columns: this.cleanColumns(this.columns),
2825
+ // filters: this.cleanFilterdColumns(),
2826
+ // no_of_records: this.paginationConfig.pageSize,
2827
+ // table_config: {
2828
+ // rowShadingEnabled: this.rowShadingEnabled || false,
2829
+ // showVerticalBorder: this.showVerticalBorder || false,
2830
+ // fontFaimly: this.fontFaimly || 'Inter',
2831
+ // headerTextFontsSize: this.headerTextColor || 14,
2832
+ // selectedTableLayout: this.selectedTableLayout || 'mediumd',
2833
+ // bodyTextFontsSize: this.bodyTextFontsSize || 14,
2834
+ // globalSearch: this.globalSearchText,
2835
+ // filterNames: '',
2836
+ // totalCount: 0,
2837
+ // activeFilters: true,
2838
+ // oddRowsBackgroundColor: '#f1f1f1'
2839
+ // },
2840
+ // type: this.tableType,
2841
+ // };
2842
+ // this.createUpdateConfigListing.emit(this.createUpdateColumnConfig);
2843
+ // };
2844
+ // window.addEventListener('mousemove', onMouseMove);
2845
+ // window.addEventListener('mouseup', onMouseUp);
2846
+ // }
2847
+ onResizeGroup(event, col, isRightPinned = false) {
2768
2848
  event.preventDefault();
2769
2849
  event.stopPropagation();
2770
2850
  const startX = event.clientX;
2771
- const children = col.children || [];
2772
- if (!children.length)
2851
+ const children = col.children;
2852
+ if (!children?.length)
2773
2853
  return;
2774
- const childWidths = children.map((child) => {
2775
- const el = document.querySelector(`[field="${child.field}"]`);
2854
+ // 🔥 Cache DOM + initial widths once
2855
+ const childMeta = children.map((child) => {
2856
+ const elements = Array.from(document.querySelectorAll(`[field="${child.field}"]`));
2857
+ const width = elements[0]?.offsetWidth || 80;
2776
2858
  return {
2777
2859
  field: child.field,
2778
- width: el?.offsetWidth || 0,
2860
+ elements,
2861
+ initialWidth: width,
2862
+ ratio: 0,
2863
+ finalWidth: width
2779
2864
  };
2780
2865
  });
2781
- const totalInitialWidth = childWidths.reduce((sum, col) => sum + col.width, 0);
2866
+ const totalInitialWidth = childMeta.reduce((sum, c) => sum + c.initialWidth, 0);
2867
+ // 🔥 Precompute ratios once
2868
+ for (const child of childMeta) {
2869
+ child.ratio = child.initialWidth / totalInitialWidth;
2870
+ }
2871
+ // 🔥 Cache group header once
2872
+ const groupHeaderEl = document.querySelector(`[group="${col.header}"]`);
2873
+ let latestDelta = 0;
2874
+ let rafId = null;
2875
+ const applyWidths = () => {
2876
+ rafId = null;
2877
+ let totalNewWidth = 0;
2878
+ for (const child of childMeta) {
2879
+ const newWidth = Math.max(child.initialWidth + latestDelta * child.ratio, 80);
2880
+ child.finalWidth = newWidth;
2881
+ totalNewWidth += newWidth;
2882
+ const widthPx = `${newWidth}px`;
2883
+ for (const el of child.elements) {
2884
+ el.style.width = widthPx;
2885
+ el.style.minWidth = widthPx;
2886
+ }
2887
+ }
2888
+ if (groupHeaderEl) {
2889
+ groupHeaderEl.style.width = `${totalNewWidth}px`;
2890
+ }
2891
+ };
2782
2892
  const onMouseMove = (moveEvent) => {
2783
2893
  let deltaX = moveEvent.clientX - startX;
2784
- if (isRightPinned) {
2894
+ if (isRightPinned)
2785
2895
  deltaX = -deltaX;
2786
- }
2787
- // Prevent shrinking too small
2896
+ // 🔥 Prevent shrinking below min
2788
2897
  if (totalInitialWidth + deltaX < children.length * 80)
2789
2898
  return;
2790
- let totalNewWidth = 0;
2791
- childWidths.forEach((child) => {
2792
- const ratio = child.width / totalInitialWidth;
2793
- const newWidth = Math.max(child.width + deltaX * ratio, 80);
2794
- totalNewWidth += newWidth;
2795
- const childEls = document.querySelectorAll(`[field="${child.field}"]`);
2796
- childEls.forEach((el) => {
2797
- const elHtml = el;
2798
- elHtml.style.minWidth = `${newWidth}px`;
2799
- elHtml.style.width = `${newWidth}px`;
2800
- });
2801
- this.updateColumnWidthInSourceByField(child.field, newWidth);
2802
- });
2803
- // ✅ Update group header width in DOM
2804
- const groupHeaderEl = document.querySelector(`[group="${col.header}"]`);
2805
- if (groupHeaderEl) {
2806
- groupHeaderEl.style.width = `${totalNewWidth}px`;
2899
+ latestDelta = deltaX;
2900
+ if (rafId === null) {
2901
+ rafId = requestAnimationFrame(applyWidths);
2807
2902
  }
2808
2903
  };
2809
2904
  const onMouseUp = () => {
2905
+ // 🔥 Commit widths ONCE
2906
+ for (const child of childMeta) {
2907
+ this.updateColumnWidthInSourceByField(child.field, child.finalWidth);
2908
+ }
2810
2909
  if (this.tableFilterViewId) {
2811
2910
  this.savePreset('mouseUp');
2812
2911
  }
2813
2912
  this.refreshHeaders();
2913
+ this.createUpdateConfigListing.emit(this.createUpdateColumnConfig);
2814
2914
  window.removeEventListener('mousemove', onMouseMove);
2815
2915
  window.removeEventListener('mouseup', onMouseUp);
2816
- const sendData = {
2817
- columns: this.cleanColumns(this.columns),
2818
- filters: this.cleanFilterdColumns(),
2819
- no_of_records: this.paginationConfig.pageSize,
2820
- table_config: {
2821
- rowShadingEnabled: this.rowShadingEnabled || false,
2822
- showVerticalBorder: this.showVerticalBorder || false,
2823
- fontFaimly: this.fontFaimly || 'Inter',
2824
- headerTextFontsSize: this.headerTextColor || 14,
2825
- selectedTableLayout: this.selectedTableLayout || 'mediumd',
2826
- bodyTextFontsSize: this.bodyTextFontsSize || 14,
2827
- globalSearch: this.globalSearchText,
2828
- filterNames: '',
2829
- totalCount: 0,
2830
- activeFilters: true,
2831
- oddRowsBackgroundColor: '#f1f1f1'
2832
- },
2833
- type: this.tableType,
2834
- };
2835
- this.createUpdateConfigListing.emit(this.createUpdateColumnConfig);
2916
+ if (rafId !== null) {
2917
+ cancelAnimationFrame(rafId);
2918
+ }
2836
2919
  };
2837
- window.addEventListener('mousemove', onMouseMove);
2838
- window.addEventListener('mouseup', onMouseUp);
2920
+ window.addEventListener('mousemove', onMouseMove, { passive: true });
2921
+ window.addEventListener('mouseup', onMouseUp, { once: true });
2839
2922
  }
2840
2923
  updateColumnWidthInSourceByField(field, width) {
2841
2924
  const update = (columns) => {
@@ -2894,63 +2977,123 @@ class DataGridComponent {
2894
2977
  };
2895
2978
  });
2896
2979
  }
2980
+ // onResizeColumn(event: MouseEvent, col: any): void {
2981
+ // event.preventDefault();
2982
+ // event.stopPropagation();
2983
+ // const startX = event.clientX;
2984
+ // const targetEl = document.querySelector(
2985
+ // `[field="${col.field}"]`
2986
+ // ) as HTMLElement;
2987
+ // const initialWidth = targetEl?.offsetWidth || 150;
2988
+ // const matchingEls = document.querySelectorAll(`[field="${col.field}"]`);
2989
+ // // 👉 Add highlight while resizing
2990
+ // if (col?.pinned == 'right') {
2991
+ // matchingEls.forEach((el: Element) => {
2992
+ // (el as HTMLElement).classList.add('resizing-highlight-right');
2993
+ // });
2994
+ // } else {
2995
+ // matchingEls.forEach((el: Element) => {
2996
+ // (el as HTMLElement).classList.add('resizing-highlight');
2997
+ // });
2998
+ // }
2999
+ // const onMouseMove = (moveEvent: MouseEvent) => {
3000
+ // let deltaX = moveEvent.clientX - startX;
3001
+ // // 👉 Reverse if the column is pinned to the right
3002
+ // if (col.pinned === 'right') {
3003
+ // deltaX = -deltaX;
3004
+ // }
3005
+ // let newWidth = initialWidth + deltaX;
3006
+ // if (newWidth < 80) return;
3007
+ // matchingEls.forEach((el: Element) => {
3008
+ // const element = el as HTMLElement;
3009
+ // element.style.minWidth = `${newWidth}px`;
3010
+ // element.style.width = `${newWidth}px`;
3011
+ // });
3012
+ // this.updateColumnWidthInSourceByField(col.field, newWidth);
3013
+ // col.width = newWidth;
3014
+ // this.hasScroll = this.hasHorizontalScrollbar();
3015
+ // };
3016
+ // const onMouseUp = () => {
3017
+ // if (this.tableFilterViewId) {
3018
+ // this.savePreset('mouseUp');
3019
+ // }
3020
+ // this.refreshHeaders();
3021
+ // const sendData = {
3022
+ // columns: this.cleanColumns(this.columns),
3023
+ // filters: this.cleanFilterdColumns(),
3024
+ // no_of_records: this.paginationConfig.pageSize,
3025
+ // type: this.tableType,
3026
+ // };
3027
+ // this.createUpdateConfigListing.emit(this.createUpdateColumnConfig);
3028
+ // matchingEls.forEach((el: Element) => {
3029
+ // (el as HTMLElement).classList.remove('resizing-highlight');
3030
+ // (el as HTMLElement).classList.remove('resizing-highlight-right');
3031
+ // });
3032
+ // window.removeEventListener('mousemove', onMouseMove);
3033
+ // window.removeEventListener('mouseup', onMouseUp);
3034
+ // };
3035
+ // window.addEventListener('mousemove', onMouseMove);
3036
+ // window.addEventListener('mouseup', onMouseUp);
3037
+ // }
2897
3038
  onResizeColumn(event, col) {
2898
3039
  event.preventDefault();
2899
3040
  event.stopPropagation();
2900
3041
  const startX = event.clientX;
2901
- const targetEl = document.querySelector(`[field="${col.field}"]`);
2902
- const initialWidth = targetEl?.offsetWidth || 150;
2903
- const matchingEls = document.querySelectorAll(`[field="${col.field}"]`);
2904
- // 👉 Add highlight while resizing
2905
- if (col?.pinned == 'right') {
2906
- matchingEls.forEach((el) => {
2907
- el.classList.add('resizing-highlight-right');
2908
- });
2909
- }
2910
- else {
2911
- matchingEls.forEach((el) => {
2912
- el.classList.add('resizing-highlight');
2913
- });
2914
- }
3042
+ // 🔥 Cache DOM once
3043
+ const elements = Array.from(document.querySelectorAll(`[field="${col.field}"]`));
3044
+ if (!elements.length)
3045
+ return;
3046
+ const initialWidth = elements[0].offsetWidth || 150;
3047
+ const isRightPinned = col.pinned === 'right';
3048
+ const highlightClass = isRightPinned
3049
+ ? 'resizing-highlight-right'
3050
+ : 'resizing-highlight';
3051
+ // 🔥 Add highlight once
3052
+ elements.forEach(el => el.classList.add(highlightClass));
3053
+ let latestWidth = initialWidth;
3054
+ let rafId = null;
3055
+ const applyWidth = () => {
3056
+ rafId = null;
3057
+ const widthPx = `${latestWidth}px`;
3058
+ for (const el of elements) {
3059
+ el.style.width = widthPx;
3060
+ el.style.minWidth = widthPx;
3061
+ }
3062
+ };
2915
3063
  const onMouseMove = (moveEvent) => {
2916
3064
  let deltaX = moveEvent.clientX - startX;
2917
- // 👉 Reverse if the column is pinned to the right
2918
- if (col.pinned === 'right') {
3065
+ if (isRightPinned)
2919
3066
  deltaX = -deltaX;
2920
- }
2921
- let newWidth = initialWidth + deltaX;
3067
+ const newWidth = initialWidth + deltaX;
2922
3068
  if (newWidth < 80)
2923
3069
  return;
2924
- matchingEls.forEach((el) => {
2925
- const element = el;
2926
- element.style.minWidth = `${newWidth}px`;
2927
- element.style.width = `${newWidth}px`;
2928
- });
2929
- this.updateColumnWidthInSourceByField(col.field, newWidth);
2930
- col.width = newWidth;
2931
- this.hasScroll = this.hasHorizontalScrollbar();
3070
+ latestWidth = newWidth;
3071
+ // 🔥 Throttle DOM writes to animation frame
3072
+ if (rafId === null) {
3073
+ rafId = requestAnimationFrame(applyWidth);
3074
+ }
2932
3075
  };
2933
3076
  const onMouseUp = () => {
3077
+ // 🔥 Finalize state ONCE
3078
+ col.width = latestWidth;
3079
+ this.updateColumnWidthInSourceByField(col.field, latestWidth);
3080
+ // 🔥 Run expensive logic once
3081
+ this.hasScroll = this.hasHorizontalScrollbar();
2934
3082
  if (this.tableFilterViewId) {
2935
3083
  this.savePreset('mouseUp');
2936
3084
  }
2937
3085
  this.refreshHeaders();
2938
- const sendData = {
2939
- columns: this.cleanColumns(this.columns),
2940
- filters: this.cleanFilterdColumns(),
2941
- no_of_records: this.paginationConfig.pageSize,
2942
- type: this.tableType,
2943
- };
2944
3086
  this.createUpdateConfigListing.emit(this.createUpdateColumnConfig);
2945
- matchingEls.forEach((el) => {
2946
- el.classList.remove('resizing-highlight');
2947
- el.classList.remove('resizing-highlight-right');
2948
- });
3087
+ // 🔥 Cleanup
3088
+ elements.forEach(el => el.classList.remove(highlightClass));
2949
3089
  window.removeEventListener('mousemove', onMouseMove);
2950
3090
  window.removeEventListener('mouseup', onMouseUp);
3091
+ if (rafId !== null) {
3092
+ cancelAnimationFrame(rafId);
3093
+ }
2951
3094
  };
2952
- window.addEventListener('mousemove', onMouseMove);
2953
- window.addEventListener('mouseup', onMouseUp);
3095
+ window.addEventListener('mousemove', onMouseMove, { passive: true });
3096
+ window.addEventListener('mouseup', onMouseUp, { once: true });
2954
3097
  }
2955
3098
  onResizeGroupBox(event) {
2956
3099
  event.preventDefault();
@@ -3797,7 +3940,7 @@ class DataGridComponent {
3797
3940
  this.pendingAnimationFrame = requestAnimationFrame(() => {
3798
3941
  const scrollingDown = scrollTop > this.lastScrollTop;
3799
3942
  this.lastScrollTop = scrollTop;
3800
- const overscan = 0;
3943
+ const overscan = 4;
3801
3944
  const newStartIndex = Math.floor(scrollTop / this.rowHeight);
3802
3945
  // const dynamicOverscan = scrollingDown ? overscan : overscan;
3803
3946
  const start = Math.max(0, newStartIndex - overscan);
@@ -4560,7 +4703,7 @@ class DataGridComponent {
4560
4703
  this.createUpdateConfigListing.emit(this.createUpdateColumnConfig);
4561
4704
  const filters = this.cleanFilterdColumns();
4562
4705
  setTimeout(() => {
4563
- this.commonSevice.mainContainerLeft = this.centerScrollableBody.nativeElement.scrollLeft;
4706
+ this.commonSevice.mainContainerLeft = this.centerPinnedHeader.nativeElement.scrollLeft;
4564
4707
  this.filterOptions.emit(filters);
4565
4708
  }, 200);
4566
4709
  }
@@ -4665,7 +4808,7 @@ class DataGridComponent {
4665
4808
  this.createUpdateConfigListing.emit(this.createUpdateColumnConfig);
4666
4809
  const filters = this.cleanFilterdColumns();
4667
4810
  setTimeout(() => {
4668
- this.commonSevice.mainContainerLeft = this.centerScrollableBody.nativeElement.scrollLeft;
4811
+ this.commonSevice.mainContainerLeft = this.centerPinnedHeader.nativeElement.scrollLeft;
4669
4812
  this.filterOptions.emit(filters);
4670
4813
  }, 200);
4671
4814
  }
@@ -4711,8 +4854,8 @@ class DataGridComponent {
4711
4854
  if (!shouldUpdateConfigListing) {
4712
4855
  this.createUpdateConfigListing.emit(this.createUpdateColumnConfig);
4713
4856
  }
4714
- this.commonSevice.mainContainerLeft = this.centerScrollableBody.nativeElement.scrollLeft;
4715
- this.commonSevice.mainContainerLeft = this.centerScrollableBody.nativeElement.scrollLeft;
4857
+ this.commonSevice.mainContainerLeft = this.centerPinnedHeader.nativeElement.scrollLeft;
4858
+ // this.commonSevice.mainContainerLeft = this.centerPinnedHeader.nativeElement.scrollLeft;
4716
4859
  setTimeout(() => {
4717
4860
  const filteredColumns = this.cleanFilterdColumns();
4718
4861
  this.genericEvent.emit(event);
@@ -4758,7 +4901,7 @@ class DataGridComponent {
4758
4901
  type: this.tableType,
4759
4902
  };
4760
4903
  this.createUpdateConfigListing.emit(this.createUpdateColumnConfig);
4761
- this.commonSevice.mainContainerLeft = this.centerScrollableBody.nativeElement.scrollLeft;
4904
+ this.commonSevice.mainContainerLeft = this.centerPinnedHeader.nativeElement.scrollLeft;
4762
4905
  setTimeout(() => {
4763
4906
  const filteredColumns = this.cleanFilterdColumns();
4764
4907
  this.filterOptions.emit(filteredColumns);
@@ -4788,7 +4931,7 @@ class DataGridComponent {
4788
4931
  type: this.tableType,
4789
4932
  };
4790
4933
  this.createUpdateConfigListing.emit(this.createUpdateColumnConfig);
4791
- this.commonSevice.mainContainerLeft = this.centerScrollableBody.nativeElement.scrollLeft;
4934
+ this.commonSevice.mainContainerLeft = this.centerPinnedHeader.nativeElement.scrollLeft;
4792
4935
  setTimeout(() => {
4793
4936
  const filteredColumns = this.cleanFilterdColumns();
4794
4937
  this.filterOptions.emit(filteredColumns);
@@ -5144,7 +5287,7 @@ class DataGridComponent {
5144
5287
  },
5145
5288
  eventType: 'pageChange',
5146
5289
  };
5147
- this.commonSevice.mainContainerLeft = this.centerScrollableBody.nativeElement.scrollLeft;
5290
+ this.commonSevice.mainContainerLeft = this.centerPinnedHeader.nativeElement.scrollLeft;
5148
5291
  this.genericEvent.emit(event);
5149
5292
  }
5150
5293
  onPageSizeChange() {