Home  >  Q&A  >  body text

How to check last record in table in Angular

<p>I have this table row</p> <pre class="brush:php;toolbar:false;"><tbody> <tr *ngFor="let data of List | paginate : { itemsPerPage: 10, currentPage: p }; let i = index"> <td>{{ data.Name }}</td> <td> </td> ... </tr> </tbody></pre> <p>I want to check the last record of each page. Suppose there are 12 records, and each page has <code>10</code>, then another page has <code>2</code> strips, I want to check the last record of each page and apply CSS style on the last record of each page. </p> <p>Is there any solution? Thank you</p>
P粉668146636P粉668146636433 days ago364

reply all(1)I'll reply

  • P粉578343994

    P粉5783439942023-08-15 11:33:59

    You have two choices.

    Option 1: Conditionally apply a class using ngClass

    <tr *ngFor="let data of List | paginate : { itemsPerPage: 10, currentPage: p }; let last = last" [ngClass]="{ yourclass: last }">

    Option 2: Select the last tr

    in your stylesheet
    tr:last-of-type {
      // 你的样式
    }

    reply
    0
  • Cancelreply