分页无法正常工作

时间:2021-03-25 12:34:21

标签: angular

我有一个表格,我在其中使用 ngx-pagination 应用了分页。表中的列表也有编辑和删除图标。当我编辑第二页上的列表数据之一并提交时,它会重定向到第一页。我希望当从 1 以外的页面完成任何编辑时,在保存编辑后,它只保留在该页面上。我怎样才能做到这一点???

component.html

       <table class="table tabs">
      <thead>
        <tr>
          <th>S. No.</th>
          <th>Name</th>
          <th></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr
          *ngFor="
            let con of getAnaInfo
              | filter: searchText
              | paginate
                : {
                    itemsPerPage: itemsPerPage,
                    currentPage: currentPage,
                    totalItems: totalItems
                  };
            let i = index
          "
        >
          <td>{{ (currentPage - 1) * itemsPerPage + i + 1 }}</td>
          <td>{{ con.Status }}</td>
          <td>{{ con.Rules.RuleName }}</td>
          <td><i class="fa fa-pencil" (click)="edit(con.Id, 
   currentPage)"></i></td>
         
        </tr>
      </tbody>
    </table>

component.ts

       edit(id, currentPage) {    
   this.router.navigate(["/dashboard/details/edit-page/" + id]);
    }

当从第 2 页或更多页触发“编辑”功能时,它会被重定向到另一个页面“editPageComponent.html”,当我提交时,它会返回到第一页。

editPageComponent.ts

 saveEdit(){      
  this.service
    .info(id,Info)
    .subscribe(
      (data: any) => {
        if (data.status == "success") {
          this.toastrService.success(data.message);             
          this.router.navigate([
            "/dashboard/details/list-data",
          ],
         );
        } else {
          this.toastrService.error(data.message);
        }
      }
     }

1 个答案:

答案 0 :(得分:0)

您可以尝试在触发 currentPage 时保持相同的 edit() 值。