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

fix(1605): remove duplicate templateref contents when navigating pages #1606

Merged
merged 2 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions demo/src/app/advanced/using-ng-template-ref.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,26 @@ describe('UsingNgTemplateRefComponent', () => {

});

it('should not have duplicate contents in ngTemplateRef column when navigating pages', async () => {
await fixture.whenStable();
fixture.detectChanges();

const query = fixture.debugElement.query(By.directive(DataTableDirective));
const dir = query.injector.get(DataTableDirective);
expect(dir).toBeTruthy();

// trigger pagination events
(await dir.dtInstance).page(2).draw(false);
await fixture.whenRenderingDone();

(await dir.dtInstance).page(0).draw(false);
await fixture.whenRenderingDone();
fixture.detectChanges();

// verify no duplication
const firstRow = fixture.debugElement.query(By.css('tbody'));
const templatedCell = firstRow.children[0].children[3];
expect(templatedCell.children.length).toBe(1);
});

});
2 changes: 2 additions & 0 deletions src/angular-datatables.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export class DataTableDirective implements OnDestroy, OnInit {
// get <td> element which holds data using index
const i = columns.findIndex(e => e.data === el.data);
const cellFromIndex = row.childNodes.item(i);
// reset cell before applying transform
$(cellFromIndex).html('');
// render onto DOM
// finalize context to be sent to user
const _context = Object.assign({}, context, context?.userData, {
Expand Down