From f64aba89f71227db1c9d009fd75a3dd06b218bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Thu, 15 Aug 2024 10:04:51 +0300 Subject: [PATCH] Fixed #16182 - p-table triggers lazy loading event twice --- src/app/components/table/table.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index c5fba8770c2..c65318b4e85 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -1577,9 +1577,9 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable this.restoringSort = false; } - this.lazy && this.onLazyLoad.emit(this.createLazyLoadMetadata()); - - if (this.value) { + if (this.lazy) { + this.onLazyLoad.emit(this.createLazyLoadMetadata()); + } else if (this.value) { if (this.customSort) { this.sortFunction.emit({ data: this.value, @@ -1587,7 +1587,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable field: field, order: order }); - } else if (!this.lazy) { + } else { this.value.sort((data1, data2) => { let value1 = ObjectUtils.resolveFieldData(data1, field); let value2 = ObjectUtils.resolveFieldData(data2, field); @@ -1605,7 +1605,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable this._value = [...this.value]; } - if ((!this.lazy || this.customSort) && this.hasFilter()) { + if (this.hasFilter()) { this._filter(); } } @@ -1627,15 +1627,16 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable } if (this.multiSortMeta) { - this.lazy && this.onLazyLoad.emit(this.createLazyLoadMetadata()); - if (this.value) { + if (this.lazy) { + this.onLazyLoad.emit(this.createLazyLoadMetadata()); + } else if (this.value) { if (this.customSort) { this.sortFunction.emit({ data: this.value, mode: this.sortMode, multiSortMeta: this.multiSortMeta }); - } else if (!this.lazy) { + } else { this.value.sort((data1, data2) => { return this.multisortField(data1, data2, this.multiSortMeta, 0); }); @@ -1643,7 +1644,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable this._value = [...this.value]; } - if ((!this.lazy || this.customSort) && this.hasFilter()) { + if (this.hasFilter()) { this._filter(); } }