@universis/ngx-tables 0.8.1 → 0.8.3

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.
@@ -24,7 +24,7 @@ import { __extends, __awaiter, __generator, __values, __assign, __spread } from
24
24
  import { Injectable, Directive, Optional, Input, Pipe, Component, ElementRef, ViewChild, ViewEncapsulation, EventEmitter, Output, NgModule, CUSTOM_ELEMENTS_SCHEMA, defineInjectable, inject, HostListener, ChangeDetectorRef, InjectionToken, Inject, Injector, ChangeDetectionStrategy } from '@angular/core';
25
25
  import { ActivatedRoute, Router, NavigationStart, NavigationEnd, RouterModule } from '@angular/router';
26
26
  import { createFeatureSelector, createSelector, select, Store } from '@ngrx/store';
27
- import { first, filter } from 'rxjs/operators';
27
+ import { skip, first, filter } from 'rxjs/operators';
28
28
 
29
29
  var AdvancedColumnFormatter = /** @class */ (function () {
30
30
  function AdvancedColumnFormatter() {
@@ -825,10 +825,20 @@ var ActivatedTableService = /** @class */ (function () {
825
825
  var _this = this;
826
826
  this._router = _router;
827
827
  this._activatedRoute = _activatedRoute;
828
+ /**
829
+ * Get the last table that was set as active
830
+ * Note: Emitted value may be null (e.g. reset on route changes)
831
+ */
832
+ this.lastActiveTable = new BehaviorSubject(null);
833
+ /**
834
+ * Omit the last emitted value to observe only new active table changes
835
+ * Note: Emitted value may be null (e.g. reset on route changes)
836
+ */
837
+ this.nextActiveTable = this.lastActiveTable.pipe(skip(1));
828
838
  _router.events.forEach(function (event) {
829
839
  if (event instanceof NavigationStart) {
830
840
  if (_this._activeTable) {
831
- _this._activeTable = null;
841
+ _this.activeTable = null;
832
842
  }
833
843
  }
834
844
  });
@@ -839,6 +849,8 @@ var ActivatedTableService = /** @class */ (function () {
839
849
  },
840
850
  set: function (tableComponent) {
841
851
  this._activeTable = tableComponent;
852
+ // provide change to observers
853
+ this.lastActiveTable.next(this._activeTable);
842
854
  },
843
855
  enumerable: true,
844
856
  configurable: true
@@ -1769,8 +1781,9 @@ var AdvancedTableComponent = /** @class */ (function () {
1769
1781
  if (_this.dataTable) {
1770
1782
  var info = _this.dataTable.page.info();
1771
1783
  _this.page.emit(info);
1772
- if (drawIndex_1 > 1)
1784
+ if (drawIndex_1 > 1) {
1773
1785
  return;
1786
+ }
1774
1787
  try {
1775
1788
  drawIndex_1++;
1776
1789
  setTimeout(function () { _this.dataTable.columns.adjust(); }, 1);
@@ -1909,7 +1922,7 @@ var AdvancedTableComponent = /** @class */ (function () {
1909
1922
  // get order expression
1910
1923
  var order = aoData[2].value;
1911
1924
  // get skip records param
1912
- var skip = aoData[3].value;
1925
+ var skip$$1 = aoData[3].value;
1913
1926
  // get page size param
1914
1927
  var top = aoData[4].value;
1915
1928
  // get search value
@@ -1918,7 +1931,7 @@ var AdvancedTableComponent = /** @class */ (function () {
1918
1931
  var q = self._query instanceof ClientDataQueryable ? self._query : self._context.model(self.config.model).asQueryable();
1919
1932
  // apply paging params
1920
1933
  if (top) {
1921
- q.take(top).skip(skip);
1934
+ q.take(top).skip(skip$$1);
1922
1935
  }
1923
1936
  // apply order params
1924
1937
  if (order && order.length) {
@@ -2349,7 +2362,7 @@ var AdvancedTableComponent = /** @class */ (function () {
2349
2362
  var index = columnOrder.indexOf(i);
2350
2363
  var visible = _this.dataTable.column(index).visible();
2351
2364
  // set title for select column
2352
- if (i == 0 && _this.selectable) {
2365
+ if (i === 0 && _this.selectable) {
2353
2366
  title = '<' + _this._translateService.instant('Tables.SelectColumn') + '>';
2354
2367
  }
2355
2368
  // get column title
@@ -2383,9 +2396,18 @@ var AdvancedTableComponent = /** @class */ (function () {
2383
2396
  });
2384
2397
  this._columnSelector.selectColumns(columns).then(function (event) {
2385
2398
  if (event.result === 'ok') {
2399
+ var sorted = event.columns
2400
+ .map(function (col) {
2401
+ return {
2402
+ key: col.key,
2403
+ index: col.index
2404
+ };
2405
+ })
2406
+ .sort(function (a, b) { return a.index - b.index; });
2386
2407
  // get column order e.g. [3, 1, 2, 0, 4]
2387
- var indexes = event.columns.map(function (item) {
2388
- return item.index;
2408
+ var indexes = sorted
2409
+ .map(function (item) {
2410
+ return event.columns.findIndex(function (next) { return item.key === next.key; });
2389
2411
  });
2390
2412
  // reset column visibilty
2391
2413
  for (var index = 0; index < event.columns.length; index++) {
@@ -2499,12 +2521,10 @@ var AdvancedTableComponent = /** @class */ (function () {
2499
2521
  cleanupIndexes.push(index);
2500
2522
  return false;
2501
2523
  }
2502
- // find item by title
2503
- var findItem = _this.config.columns.find(function (column) {
2504
- return column.title && column.title.length && _this._translateService.instant(column.title) === headerItem;
2505
- });
2506
2524
  // exclude hidden columns
2507
- if (findItem && findItem.hidden === true) {
2525
+ // note: use the datatable visible() function
2526
+ // instead of the hidden config property, to satisfy the column selector
2527
+ if (!_this.dataTable.column(index).visible()) {
2508
2528
  cleanupIndexes.push(index);
2509
2529
  return false;
2510
2530
  }
@@ -5339,7 +5359,10 @@ var AdvancedTableState = /** @class */ (function () {
5339
5359
  this.table.stateSave = true;
5340
5360
  this.table.stateLoadCallback = function (settings, callback) {
5341
5361
  _this.store.pipe(select(selectTable, { id: _this.tableState }), first()).subscribe(function (state) {
5342
- return callback(state && state.table);
5362
+ callback(state && state.table);
5363
+ if (state && state.table && state.table.ColReorder) {
5364
+ _this.table.dataTable.colReorder.order(state.table.ColReorder, true);
5365
+ }
5343
5366
  });
5344
5367
  };
5345
5368
  var firstDraw = true;