@datorama/core 22.7.0 → 22.8.0

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.
@@ -10097,7 +10097,7 @@ let GridQuery = class GridQuery extends Query {
10097
10097
  const storeSettings = this.getValue().settings;
10098
10098
  const settings = {
10099
10099
  gridAlignment: storeSettings.gridAlignment,
10100
- sort: this.getSort(),
10100
+ sort: this.getGridOptions().sortByStore ? this.getSavedSort() : this.getSortModel(),
10101
10101
  hiddenColumns,
10102
10102
  groupedColumns: groupedColumns.map(toColId),
10103
10103
  filter: this.getFilter(),
@@ -10111,30 +10111,31 @@ let GridQuery = class GridQuery extends Query {
10111
10111
  }
10112
10112
  return settings;
10113
10113
  }
10114
- getSort() {
10114
+ getSortModel() {
10115
10115
  return this.api.grid.getSortModel().pop();
10116
10116
  }
10117
- getExternalSort() {
10118
- const { sort, colId } = this.getSort() || {};
10119
- const column = this.api.columns.getColumn(colId);
10120
- const allColumns = this.api.columns.getAllGridColumns();
10121
- if (column) {
10122
- return { colId, sort, field: getColField(column.getColDef()), sortIndex: allColumns.indexOf(column) };
10123
- }
10124
- else {
10125
- const secondaryColumn = this.getSecondaryColumn(colId);
10126
- if (secondaryColumn) {
10127
- return {
10128
- colId,
10129
- sort,
10130
- field: getColField(secondaryColumn.getColDef()),
10131
- sortIndex: allColumns.indexOf(secondaryColumn)
10132
- };
10117
+ getSavedSort() {
10118
+ return this.getValue().settings.sort || this.getSortModel();
10119
+ }
10120
+ getSort(savedSort = this.getSavedSort()) {
10121
+ if (savedSort) {
10122
+ const { colId, sort, sortIndex } = savedSort;
10123
+ const column = this.api.columns.getColumn(colId);
10124
+ const allColumns = this.api.columns.getAllGridColumns();
10125
+ if (column) {
10126
+ const field = getColField(column.getColDef());
10127
+ return { colId, sort, field };
10128
+ }
10129
+ else {
10130
+ const secondaryColumn = this.getSecondaryColumn(colId);
10131
+ if (secondaryColumn) {
10132
+ const columnIndex = sortIndex || allColumns.indexOf(secondaryColumn);
10133
+ const field = getColField(secondaryColumn.getColDef());
10134
+ return { colId, sort, field, sortIndex: columnIndex };
10135
+ }
10133
10136
  }
10134
10137
  }
10135
- }
10136
- selectSort() {
10137
- return this.select(state => state.settings.sort);
10138
+ return { colId: null, sort: null };
10138
10139
  }
10139
10140
  /* @internal */
10140
10141
  _setApi(api, gridRef) {
@@ -11835,6 +11836,7 @@ let DatoGridColumnHeaderComponent = class DatoGridColumnHeaderComponent {
11835
11836
  const sortingOrder = this.column.getColDef() ? this.column.getColDef().sortingOrder : null;
11836
11837
  let sort;
11837
11838
  const currentSort = this.column.getSort();
11839
+ const colId = this.column.getColId();
11838
11840
  if (sortingOrder && sortingOrder.length > 0) {
11839
11841
  const currentSortIndex = sortingOrder.indexOf(currentSort);
11840
11842
  let newSortIndex;
@@ -11851,10 +11853,15 @@ let DatoGridColumnHeaderComponent = class DatoGridColumnHeaderComponent {
11851
11853
  }
11852
11854
  gridService._logEvent("Grids - Column Action" /* GRID_COLUMN_ACTION */, {
11853
11855
  action: 'Sort',
11854
- column: this.column.getColId()
11856
+ column: colId
11855
11857
  });
11856
11858
  gridQuery.isServerSide && gridService.setLoading(true);
11857
- this.params.setSort(sort);
11859
+ if (gridQuery.getGridOptions().sortByStore) {
11860
+ gridService.setSortByColumn(colId, sort);
11861
+ }
11862
+ else {
11863
+ this.params.setSort(sort);
11864
+ }
11858
11865
  });
11859
11866
  this.sortingInfo$ = gridQuery
11860
11867
  .waitForGrid(() => gridQuery.gridRef.sortChanged)
@@ -12720,21 +12727,24 @@ let GridService = class GridService {
12720
12727
  this.notifyFilterUpdate();
12721
12728
  }
12722
12729
  }
12730
+ setSortByColumn(colId, sort) {
12731
+ const sortToSet = this.gridQuery.getSort({ colId, sort });
12732
+ this.setGridSort(sortToSet);
12733
+ }
12723
12734
  setGridSort(gridSort) {
12724
- if (this.api && gridSort) {
12735
+ if (gridSort && this.api && this.api.grid.getDisplayedRowCount() > 0) {
12725
12736
  const { colId, sort, sortIndex } = gridSort;
12726
12737
  let sortToApply = gridSort;
12727
12738
  if (!isNil(sortIndex)) {
12728
12739
  const gridColumns = this.api.columns.getAllGridColumns();
12729
12740
  if (gridColumns) {
12730
- const secondaryColumns = this.api.columns.getSecondaryColumns();
12731
- const secondaryColumn = secondaryColumns.find((col) => col.getColId() === colId);
12732
- if (secondaryColumn) {
12741
+ const valueColumns = this.api.columns.getValueColumns();
12742
+ const valueColumn = valueColumns.find((col) => col.getColId() === colId);
12743
+ const isPivotColId = colId.startsWith('pivot');
12744
+ if (isPivotColId || valueColumn) {
12733
12745
  /** Column is pivot value column, sort by index */
12734
12746
  const columnByIndex = gridColumns[sortIndex];
12735
- if (columnByIndex) {
12736
- sortToApply = { colId: columnByIndex.getColId(), sort };
12737
- }
12747
+ sortToApply = { colId: columnByIndex.getColId(), sort, sortIndex };
12738
12748
  }
12739
12749
  else {
12740
12750
  /** Sort by column id */
@@ -13817,7 +13827,7 @@ let DatoGridControllerComponent = class DatoGridControllerComponent {
13817
13827
  const data = this.getGridData();
13818
13828
  this.onGridChange.emit({
13819
13829
  filter: this.gridQuery.getExternalFilter(),
13820
- sort: this.gridQuery.getExternalSort(),
13830
+ sort: this.gridQuery.getSort(),
13821
13831
  type,
13822
13832
  data
13823
13833
  });
@@ -22690,7 +22700,7 @@ function fixNgLeaks() {
22690
22700
  };
22691
22701
  }
22692
22702
 
22693
- window.coreVersion = '22.7.0';
22703
+ window.coreVersion = '22.8.0';
22694
22704
 
22695
22705
  /**
22696
22706
  * @license