@energycap/components 0.39.33 → 0.39.34-ECAP-26866-table-multi-sort-improvements.20241029-1608

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