Skip to content

page callback is called during initialization #2259

Description

@leanccla

Hi,
I am using version 21.1.0 of ngx-datatable.
Looks like that some behavior related to the page callback was changed.
In version 20.1.0 and older this callback was called only when the user interacts with the pager, instead now gets called even during initialization and on sort (see: #2235).

@Component({
  selector: 'client-paging-demo',
  template: `
      <ngx-datatable
        class="material"
        [rows]="rows"
        [columns]="[{ name: 'Name' }, { name: 'Gender' }, { name: 'Company' }]"
        [columnMode]="ColumnMode.force"
        [headerHeight]="50"
        [footerHeight]="50"
        rowHeight="auto"
        (page)="onPageChange($event)"
        [limit]="10"
      >
      </ngx-datatable>
  `,
  standalone: false
})
export class ClientPagingComponent {
  rows: Employee[] = [];

  ColumnMode = ColumnMode;

  constructor() {
    this.fetch(data => {
      this.rows = data;
    });
  }

  fetch(cb) {
    const req = new XMLHttpRequest();
    req.open('GET', `assets/data/company.json`);

    req.onload = () => {
      cb(JSON.parse(req.response));
    };

    req.send();
  }

  onPageChange($event: any): void {
    console.log('pageChange!');
  }
}

I think correct behavior should be to call it only when the user interact with the pager.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions