简体   繁体   English

如何在记录详细视图中添加下一个和上一个控件?

[英]How to add next and previous control in the record detail view?

If you will click on any of the record row you will see the details of the record.如果您单击任何记录行,您将看到记录的详细信息。

I wanted to add next and previous button on the details of next/previous row without click on top row.我想在下一行/上一行的详细信息上添加下一个和上一个按钮,而无需单击第一行。 So that user don't have to click again back to top row to view details.这样用户就不必再次单击回到顶行来查看详细信息。 They can simply use next / previous control to see next and previous record details.他们可以简单地使用下一个/上一个控件来查看下一个和上一个记录的详细信息。

I was trying this but didn't help.我正在尝试这个但没有帮助。

<div *ngIf="isView" class="view-details">
    <button (click)="onPrev()">Prev</button>
<button (click)="onNext()">Next</button>

component.ts组件.ts

current = 0;
  prev = -1;

  onPrev() {
    this.prev = this.allUser.current--;
    alert("Prev" + this.prev);
  }
  onNext() {
    this.prev = this.allUser.current++;
    alert("Next" + this.prev);
  }

Please help me with the solution.请帮我解决问题。

You can view the code here: https://stackblitz.com/edit/angular-ivy-1tsz1r?file=src%2Fapp%2Fapp.component.html您可以在此处查看代码: https://stackblitz.com/edit/angular-ivy-1tsz1r?file=src%2Fapp%2Fapp.component.html

You can find example here in this StackBliz Link您可以在此StackBliz 链接中找到示例

Inside you table tr click I have added new method parameter like below..在您的表格 tr 中单击我添加了新的方法参数,如下所示..

<tr class="record-row" (click)="viewUser(user, i, filteredUsers)"
                *ngFor="let user of filteredUsers;let i = index">

and Inside your component viewUser() method is...并且在您的组件 viewUser() 方法内部是...

viewUser(user: any, index, filterData) {
  this.isView = true;
  console.log(user, index, filterData);
  this.userObj = user;
  this.currentIndex = index;
  this.allUserTableData = filterData;
}

In above i have added two new class-variable currentIndex and allUserTableData .在上面我添加了两个新的类变量currentIndexallUserTableData based on this two data variable next and previous traversal is looks like below code...基于这两个数据变量的下一个和上一个遍历看起来像下面的代码......

now.. next traversal code is现在..下一个遍历代码是

nextRecord() {
   let next = (this.currentIndex += 1);
   if (next > this.allUserTableData.length - 1) {
     this.currentIndex = 5;
     return;
   }
   let nextRecord = this.allUserTableData[next];
    this.userObj = nextRecord;
    console.log(nextRecord, next);
 }

previouse traversal code is之前的遍历代码是

previousRecord() {
  let next = (this.currentIndex -= 1);
  if (next < 0) {
    this.currentIndex = 0;
    return;
  }
  let nextRecord = this.allUserTableData[next];
  this.userObj = nextRecord;
  console.log(nextRecord, next);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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