Browse Source

perf(admin-ui-plugin): Use trackBy function to improve perf of datatable

Michael Bromley 5 years ago
parent
commit
09ab4d7694

+ 1 - 1
packages/admin-ui/src/lib/core/src/shared/components/data-table/data-table.component.html

@@ -24,7 +24,7 @@
                                   currentPage: currentPage,
                                   totalItems: totalItems
                               };
-                    index as i
+                    index as i; trackBy: trackByFn
                 "
             >
                 <td *ngIf="isRowSelectedFn">

+ 8 - 0
packages/admin-ui/src/lib/core/src/shared/components/data-table/data-table.component.ts

@@ -40,4 +40,12 @@ export class DataTableComponent<T> implements AfterContentInit {
     ngAfterContentInit(): void {
         this.rowTemplate = this.templateRefs.last;
     }
+
+    trackByFn(index: number, item: any) {
+        if ((item as any).id != null) {
+            return (item as any).id;
+        } else {
+            return index;
+        }
+    }
 }