Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit c258ef4

Browse files
authored
Merge pull request #1606 from l-lin/fix-1605
fix(1605): remove duplicate templateref contents when navigating pages
2 parents e9ffeff + 345deed commit c258ef4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

demo/src/app/advanced/using-ng-template-ref.component.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,26 @@ describe('UsingNgTemplateRefComponent', () => {
7575

7676
});
7777

78+
it('should not have duplicate contents in ngTemplateRef column when navigating pages', async () => {
79+
await fixture.whenStable();
80+
fixture.detectChanges();
81+
82+
const query = fixture.debugElement.query(By.directive(DataTableDirective));
83+
const dir = query.injector.get(DataTableDirective);
84+
expect(dir).toBeTruthy();
85+
86+
// trigger pagination events
87+
(await dir.dtInstance).page(2).draw(false);
88+
await fixture.whenRenderingDone();
89+
90+
(await dir.dtInstance).page(0).draw(false);
91+
await fixture.whenRenderingDone();
92+
fixture.detectChanges();
93+
94+
// verify no duplication
95+
const firstRow = fixture.debugElement.query(By.css('tbody'));
96+
const templatedCell = firstRow.children[0].children[3];
97+
expect(templatedCell.children.length).toBe(1);
98+
});
99+
78100
});

src/angular-datatables.directive.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ export class DataTableDirective implements OnDestroy, OnInit {
126126
// get <td> element which holds data using index
127127
const i = columns.findIndex(e => e.data === el.data);
128128
const cellFromIndex = row.childNodes.item(i);
129+
// reset cell before applying transform
130+
$(cellFromIndex).html('');
129131
// render onto DOM
130132
// finalize context to be sent to user
131133
const _context = Object.assign({}, context, context?.userData, {

0 commit comments

Comments
 (0)