@sumaris-net/ngx-components 1.5.7 → 1.5.11

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.
@@ -551,7 +551,7 @@
551
551
  // Pagination (truncate if need)
552
552
  var pageData = filteredItems;
553
553
  if (opts) {
554
- if (isNil(opts.offset) && opts.offset > 0) {
554
+ if ((opts.offset || 0) > 0) {
555
555
  pageData = pageData.slice(opts.offset);
556
556
  }
557
557
  if (isNotNil(opts.size) && pageData.length > opts.size) {
@@ -24892,8 +24892,10 @@
24892
24892
  * @param opts Use interactive=false to avoid user interaction (e.g. user confirmation)
24893
24893
  */
24894
24894
  AppTable.prototype.deleteRows = function (event, rows, opts) {
24895
+ var _a;
24895
24896
  return __awaiter(this, void 0, void 0, function () {
24896
- var canDelete, saved, rowsToDelete, deleteCount, err_2;
24897
+ var confirmed, canDelete, saved, rowsToDelete, deleteCount, err_2;
24898
+ var _this = this;
24897
24899
  return __generator(this, function (_d) {
24898
24900
  switch (_d.label) {
24899
24901
  case 0:
@@ -24907,15 +24909,34 @@
24907
24909
  return [2 /*return*/, 0];
24908
24910
  if (this.loading || isEmptyArray(rows))
24909
24911
  return [2 /*return*/, 0];
24912
+ // Make sure to keep newly created row
24913
+ if (((_a = this.editedRow) === null || _a === void 0 ? void 0 : _a.id) === -1 && this.editedRow.editing && !rows.includes(this.editedRow)) {
24914
+ confirmed = this.confirmEditCreate();
24915
+ if (!confirmed)
24916
+ return [2 /*return*/, 0]; // Cannot delete (e.g. edited row is invalid)
24917
+ }
24910
24918
  return [4 /*yield*/, this.canDeleteRows(rows, opts)];
24911
24919
  case 1:
24912
24920
  canDelete = _d.sent();
24913
24921
  if (!canDelete)
24914
24922
  return [2 /*return*/, 0]; // Cannot delete
24915
24923
  if (!this.saveBeforeDelete) return [3 /*break*/, 3];
24916
- // Cancel invalid rows (because of save() will failed if there is invalid rows)
24917
- rows.filter(function (row) { var _a; return !((_a = row.validator) === null || _a === void 0 ? void 0 : _a.valid); })
24918
- .forEach(function (row) { return row.cancelOrDelete(); });
24924
+ // Cancel invalid rows (because of save() will fail, if invalid rows exists)
24925
+ rows = rows.reduce(function (res, row) {
24926
+ if (row.validator && !row.validator.valid) {
24927
+ var deleted = row.id === -1;
24928
+ row.cancelOrDelete();
24929
+ // When deleted (= newly created row) : decrement counter
24930
+ if (deleted) {
24931
+ _this.visibleRowCount--;
24932
+ _this.totalRowCount--;
24933
+ return res;
24934
+ }
24935
+ }
24936
+ return res.concat(row);
24937
+ }, []);
24938
+ if (isEmptyArray(rows))
24939
+ return [2 /*return*/, 0];
24919
24940
  return [4 /*yield*/, this.saveBeforeAction('delete')];
24920
24941
  case 2:
24921
24942
  saved = _d.sent();
@@ -24939,7 +24960,7 @@
24939
24960
  return [4 /*yield*/, this._dataSource.deleteAll(rowsToDelete)];
24940
24961
  case 5:
24941
24962
  _d.sent();
24942
- // Not need to update manually, because watchALl().subscribe() will update this count
24963
+ // DO not update manually, because watchALl().subscribe() will update this count
24943
24964
  //this.totalRowCount -= deleteCount;
24944
24965
  //this.visibleRowCount -= deleteCount;
24945
24966
  this.selection.clear();