Realizing tree-shaped secondary tables based on angular

Realizing tree-shaped secondary tables based on angular

First look at the effect:

Code:

1.html

  <div class="userContent_content">
    <div>
      <table>
        <tr>
          <td>Node name</td>
          <td>Node management IP</td>
          <td>Node login name</td> 
          <td>Node login password</td> 
        </tr>
        //Use ng-container as an empty tag to assist in placing for or if events, which cannot be found in the review element <ng-container *ngFor="let item of currentTotalList,let i = index">
          <tr>
            <td style="color: #04AEB4;cursor: pointer;" class="img">
              <div>
                <div>{{item.name}}</div>
                <div>
        //The following is a picture of an arrow, which switches between expanding and collapsing the arrow. By judging whether the current click index is equal to the list index, if it is equal, it will be expanded, otherwise it will be collapsed <img (click)="clickShowChildList(i,item.name)"
                    [attr.src]="i == currentClickOpenIndex?'../../assets/resource/img/bottom.png':'../../assets/resource/img/right.png'">
                </div>
              </div>
            </td>
            <td>{{item.ip}}</td>
            <td>{{item.username}}</td>
            <td>{{item.password}}</td>
          </tr>
        //Use the ng-container tag again to nest the child items of the table <ng-container *ngFor="let childItem of item.nodeList, let j = index">
        //Because the for loop and if judgment cannot coexist in the same tag, our hidden event if is placed in the tr tag. By judging whether the currently clicked index is consistent with the list index, it will be collapsed if they are equal, and displayed if they are not.
 
            <tr *ngIf="i == currentClickOpenIndex">
              <td style="color: #04AEB4;cursor: pointer;" class="img">
                <div>
                  <div>
                    {{childItem.masterIp}}</div>
                </div>
              </td>
              <td>{{childItem.ip}}</td>
              <td>{{childItem.username}}</td>
              <td>{{childItem.password}}</td>
            </tr>
          </ng-container>
        </ng-container>
 
      </table>
    </div>
    
  </div>

2. less

      .userContent_content{
        width: 100%;
        height: calc(~"100% - 60px");
        overflow:auto;
        >div:nth-child(1){
          >table{
            width: 100%;
            tr{
              td{
                width: 25%;
                text-align: center;
                font-size: 14px;
                color: #fff;
                padding: 16px 0px;
                box-shadow: 0 1px #333;
              }
            }
            .img {
              >div {
                width: 100%;
                display: flex;
                position: relative;
  
                >div:nth-child(1) {
                  width: 85%;
                  white-space: nowrap;
                  text-overflow: ellipsis;
                  -o-text-overflow:ellipsis;
                  overflow: hidden;
                  margin: 0 auto;
  
                }
              }
  
              img {
                height: 10px !important;
                width: 10px !important;
                margin-left: 0 !important;
                position: absolute;
                right: 0;
                top: 3px;
              }
            }
          }
        }
  
        >div:nth-child(2){
          height: 80px;
          width: 90%;
          display: flex;
          align-items: center;
          margin: 0 auto;
          justify-content: flex-end;
          #page{
            display: table;
          }
        }
      }

3.js

(1) The format of the currentTotalList table data is similar to the following (you can write a simulation data yourself):

(2) Initialize the current click index variable currentClickOpenIndex to -1

(3) is the click event of the expand and collapse arrow:

  clickShowChildList = (i,item)=>{
    console.log(i,this.currentClickOpenIndex)
    if(this.currentClickOpenIndex==i){
      this.currentClickOpenIndex = -1
    }else{
      this.currentClickOpenIndex = i
    }
  }

And then it's done...

This is the end of this article about implementing a tree-shaped secondary table based on angular. For more relevant angular tree-shaped secondary table content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • AngularJS implements table table td cell click to change input box/editable state example
  • AngularJS fuzzy query function implementation code (filter content drop-down menu sorting filter sensitive characters verification judgment and add table information)
  • Examples of basic table operations in AngularJS
  • Angular table artifact ui-grid application detailed explanation
  • Angular renders the data filled in the form into a table
  • AngularJS implements table addition, deletion, modification and query (front-end only)

<<:  Introduction to the usage of common XHTML tags

>>:  Docker image compression and optimization operations

Recommend

How to design a web page? How to create a web page?

When it comes to understanding web design, many p...

Analysis of the differences between Iframe and FRAME

1. Use of Iframe tag <br />When it comes to ...

How to configure VMware multi-node environment

This tutorial uses CentOS 7 64-bit. Allocate 2GB ...

How to split data in MySQL table and database

Table of contents 1. Vertical (longitudinal) slic...

How to install Graphviz and get started tutorial under Windows

Download and installConfigure environment variabl...

How to modify the initial password of a user in mysql5.7

When users install MySQL database for the first t...

Detailed steps for configuring virtual hosts in nginx

Virtual hosts use special software and hardware t...

Briefly describe the difference between MySQL and Oracle

1. Oracle is a large database while MySQL is a sm...

HTML head structure

The following introduces the commonly used head s...

Understanding and usage scenarios of ES6 extension operators

Table of contents 1. Replace the apply method, ge...

Nginx restricts IP access to certain pages

1. To prohibit all IP addresses from accessing th...

Collection of 25 fonts used in famous website logos

This article collects the fonts used in the logos...

mysql splits a row of data into multiple rows based on commas

Table of contents Separation effect Command line ...