l-lin / angular-datatables

DataTables with Angular
https://l-lin.github.io/angular-datatables/
MIT License
1.57k stars 481 forks source link

ngPipeInstance changes data and cause error when going back to previous page #1740

Closed erlingegelund closed 8 months ago

erlingegelund commented 1 year ago

:beetle: bug report

Using ngPipeInstance, the pipe fails when going back to previous page, causing the whole page to fail

:microscope: Minimal Reproduction

StackBlitz/GitHub Link: https://github.com/erlingegelund/ng-datatables-datepipe

Step-by-step Instructions:

  1. Start application: ng serve --open
  2. Navigate to page 2
  3. Navigate to page 1

:8ball: Expected behavior

Being able to go back and forth through the pages without errors

:camera: Screenshots

screenshot

:globe_with_meridians: Your Environment

:memo: Additional context

sune-j commented 11 months ago

I have the same issue. It seems that the result from ngPipeInstance overwrites data.

Example pipe:

transform(data: State): string {
  if (data === State.OK) {
    return 'OK';
  } else {
    return 'NOT OK'
  }
}

If State.OK is passed, the string 'OK' will be returned, but when you change page and go back to this page, data is now the string 'OK' and will return 'NOT OK'.

nymkappa commented 10 months ago

I also confirm the issue.

The bug can be reproduced in the live example at https://l-lin.github.io/angular-datatables/#/advanced/using-pipe. If you try to re-order rows, the error while be thrown in the console.

image
nymkappa commented 10 months ago

As a temporary workaround, you can use the createdCell callback from datatable, eg:

createdCell: (cell: Node, cellData: any, rowData: any, row: number, col: number) => {
   // this.number is injected in the constructor through "private number: DecimalPipe"
   $(cell).html(this.number.transform(cellData));
}
stale[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.