@sumaris-net/ngx-components 1.0.2 → 1.0.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.
@@ -522,25 +522,28 @@
522
522
  return { data: [], total: 0 };
523
523
  }
524
524
  // Filter items
525
+ var target = items;
525
526
  if (isNotNilOrBlank(value)) {
526
527
  // If wildcard, search using regexp
527
528
  if (value.indexOf('*') !== -1) {
528
529
  value = value.replace('*', '.*');
529
- items = items.filter(function (v) { return keys.findIndex(function (key) { return matchUpperCase(getPropertyByPathAsString(v, key), value); }) !== -1; });
530
+ target = target.filter(function (v) { return keys.findIndex(function (key) { return matchUpperCase(getPropertyByPathAsString(v, key), value); }) !== -1; });
530
531
  }
531
532
  // Else (no wildcard), search using startsWith
532
533
  else {
533
- items = items.filter(function (v) { return keys.findIndex(function (key) { return startsWithUpperCase(getPropertyByPathAsString(v, key), value); }) !== -1; });
534
+ target = target.filter(function (v) { return keys.findIndex(function (key) { return startsWithUpperCase(getPropertyByPathAsString(v, key), value); }) !== -1; });
534
535
  }
535
536
  }
536
537
  // Exclude ids
537
538
  if (isNotEmptyArray(opts === null || opts === void 0 ? void 0 : opts.excludedIds)) {
538
- items = items.filter(function (v) { return !opts.excludedIds.includes(+v['id']); });
539
+ target = target.filter(function (v) { return !opts.excludedIds.includes(+v['id']); });
539
540
  }
540
- // Sort
541
- items.sort(propertiesPathComparator(keys));
542
- // Truncate if need
541
+ // Sort (copy if need, before sorting)
542
+ if (target === items)
543
+ target = target.slice();
544
+ target.sort(propertiesPathComparator(keys));
543
545
  var total = items.length || 0;
546
+ // Truncate if need
544
547
  if (opts) {
545
548
  if (opts.offset > 0) {
546
549
  items = items.slice(opts.offset);