@energycap/components 0.39.31 → 0.39.32-ECAP-26866-table-multi-sort-improvements.20241022-1702

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.
@@ -7082,7 +7082,7 @@ class TableComponent {
7082
7082
  if (this.sortable && changes.sort && changes.sort.currentValue && !changes.sort.firstChange) {
7083
7083
  const newValue = changes.sort.currentValue;
7084
7084
  if (!this.currentSort || !isEqual(newValue, this.currentSort)) {
7085
- this.onSort(newValue.field, newValue.direction);
7085
+ this.onSort(newValue);
7086
7086
  }
7087
7087
  }
7088
7088
  }
@@ -7131,7 +7131,14 @@ class TableComponent {
7131
7131
  if (th.classList.contains('is-resizable') && event.target && event.target.classList.contains('handle')) {
7132
7132
  return;
7133
7133
  }
7134
- this.onSort(field);
7134
+ let direction;
7135
+ if (th.classList.contains('is-sorted-desc')) {
7136
+ direction = 'asc';
7137
+ }
7138
+ else {
7139
+ direction = 'desc';
7140
+ }
7141
+ this.onSort({ field, direction });
7135
7142
  });
7136
7143
  // Store unlisten function to remove listener when component is destroyed
7137
7144
  this.unlisteners.push(unlisten);
@@ -7143,7 +7150,7 @@ class TableComponent {
7143
7150
  });
7144
7151
  // Set the initial sort
7145
7152
  if (this.sort) {
7146
- this.onSort(this.sort.field, this.sort.direction);
7153
+ this.onSort(this.sort);
7147
7154
  }
7148
7155
  }
7149
7156
  /**
@@ -7152,32 +7159,29 @@ class TableComponent {
7152
7159
  * Emit the current field and direction of the sorted column
7153
7160
  * @param field
7154
7161
  */
7155
- onSort(field, direction) {
7156
- const th = this.sortableCols[field];
7157
- if (!th) {
7158
- return;
7159
- }
7160
- if (this.currentSort && this.currentSort.field !== field) {
7161
- this.renderer.removeClass(this.sortableCols[this.currentSort.field], `is-sorted-${this.currentSort.direction}`);
7162
- }
7163
- if (th.classList.contains('is-sorted-desc')) {
7164
- this.renderer.removeClass(th, 'is-sorted-desc');
7165
- if (!direction) {
7166
- direction = 'asc';
7167
- }
7162
+ onSort(sort) {
7163
+ this.clearSort();
7164
+ if (Array.isArray(sort)) {
7165
+ sort.forEach(s => this.applySort(s));
7168
7166
  }
7169
7167
  else {
7170
- if (th.classList.contains('is-sorted-asc')) {
7171
- this.renderer.removeClass(th, 'is-sorted-asc');
7172
- }
7173
- if (!direction) {
7174
- direction = 'desc';
7175
- }
7168
+ this.applySort(sort);
7169
+ }
7170
+ this.currentSort = cloneDeep(sort);
7171
+ this.sortChange.emit(this.currentSort);
7172
+ }
7173
+ clearSort() {
7174
+ Object.values(this.sortableCols).forEach(th => {
7175
+ this.renderer.removeClass(th, `is-sorted-asc`);
7176
+ this.renderer.removeClass(th, `is-sorted-desc`);
7177
+ });
7178
+ }
7179
+ applySort(sort) {
7180
+ const th = this.sortableCols[sort.field];
7181
+ if (!th) {
7182
+ return;
7176
7183
  }
7177
- this.renderer.addClass(th, `is-sorted-${direction}`);
7178
- const sortEvent = { field: field, direction: direction };
7179
- this.currentSort = sortEvent;
7180
- this.sortChange.emit(sortEvent);
7184
+ this.renderer.addClass(th, `is-sorted-${sort.direction}`);
7181
7185
  }
7182
7186
  initSelectable() {
7183
7187
  this.selectionContext.rowCheckboxes.valueChanges.pipe(takeUntil(this.destroyed)).subscribe((value) => {