How to make icon change only for particular table instead of changing as whole

情到浓时终转凉″ 提交于 2021-02-17 04:39:07

问题


Hi I have multiple tables looped in an array, but here if i click on icon of first table, the icon in that header name of all the tables are getting changed instead of changing to particular table.

DEMO: DEMO

TS:

 public sortContactsList(param,key) {
      this.sorting = (this.sorting === 'asc') ? 'desc' : 'asc';
      this.contactListDetails.forEach(item => {
        if (item.param === param) {
          item.icon = item.icon === 'fa fa-sort-down active' ? 'fa fa-sort-up active' : 'fa fa-sort-down active';
          this.sorting = (item.icon === 'fa fa-sort-down active') ? 'desc' : 'asc';
        }  else {
          item.icon = 'fa fa-sort'
        }
      });
  }

HTML:

  <div *ngIf="contactsDetails[0].result[key]?.length > 0">
        <h6 style="font-weight: 600;">{{key | titlecase}}</h6>
        <table class="table table-hover accordion-table" id="accordionContact">
            <thead>
                <tr>
                    <th scope="col" *ngFor="let field of contactListDetails" (click)="sortContactsList(field.param,key)">
                        {{field.displayName}}
                        <i class="{{field.icon}}" aria-hidden="true"></i>
                    </th>
                    <th scope="col" class="width125"></th>
                </tr>
            </thead>
            <tbody>
                <tr *ngFor="let fields of contactsList[key]"> 
                    <td  *ngFor="let field of contactListDetails">{{fields[field.param]}}</td>
                    <td class="width125 {{paginationDisable?'link-disabled':''}}"><button class="btn btn-outline-primary btn-table" title="Send Mail"
                            (click)="userDisplay(contactsDetails[0].result[key][0])"  [disabled]="isReadOnly && mode ==1">Email</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

来源:https://stackoverflow.com/questions/62913176/how-to-make-icon-change-only-for-particular-table-instead-of-changing-as-whole

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!