简体   繁体   中英

Angular DataTables back to the first page in pagination when click back

I have an Angular project where I am using datatables but when I am browsing in the table and I am at the page 8 for example and I click another page and click back again to the table it's resetting the pagination and show me the page 1 instead of 8

Please how to fix that?

TS

allDestinations: any[] = [];

dtOptions: DataTables.Settings = {};

ngOnInit(): void {
  this.dtOptions = {
    pagingType: 'full_numbers',
    pageLength: 25,
    processing: true,
  };

  this._DestinationsService.destinations().subscribe((data) => {
    this.allDestinations = data;
  });
}

HTML

<table class="table table-bordered table-hover my-5" *ngIf="allDestinations.length > 0" datatable
        [dtOptions]="dtOptions">

Can you add more code, like _DestinationsService code... ?

I don't know how you handle your pagination. But surely during your component initialization, it aks to get the first page of your data.

When you go on another page your component with the datable is destroy. And when you go back to your datable it is recreated and reinitialized.

One way to save the current page, it is to store the current page in your _DestinationsService , if it is a global service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM