0

HTML

 <nz-dropdown class="filter-dropdown" [nzTrigger]="'click'" nzPlacement="bottomRight">
              <a nz-dropdown nz-tooltip nzTitle="Feature not functional">
                {{ activeFilter.filterBy }} <i nz-icon [type]="activeFilter.order === 'ASC' ? 'up' : 'down'"></i>
              </a>
              <ul nz-menu>
                <li class="filter-dropdown-item" nz-menu-item  (click)="handleFilter('filterBy', 'Application')">Application</li>
                <li class="filter-dropdown-item" nz-menu-item  (click)="handleFilter('filterBy', 'Date')">
                  Date
                  <i nz-icon nzType="check" nzTheme="outline"></i>
                </li>
                <li nz-menu-divider></li>
                <li class="filter-dropdown-item" nz-menu-item  (click)="handleFilter('status', 'ALL')">All</li>
                <li class="filter-dropdown-item" nz-menu-item  (click)="handleFilter('status', 'ACK')">Acknowledged</li>
                <li class="filter-dropdown-item" nz-menu-item  (click)="handleFilter('status', 'READ')">Read</li>
                <li class="filter-dropdown-item" nz-menu-item  (click)="handleFilter('status', 'NEW')">New</li>
                <li nz-menu-divider></li>
                <li class="filter-dropdown-item" nz-menu-item  (click)="handleFilter('order', 'ASC')">Ascending</li>
                <li class="filter-dropdown-item" nz-menu-item  (click)="handleFilter('order', 'DESC')">Descending</li>
                <li nz-menu-divider></li>
                <li class="filter-dropdown-item" nz-menu-item  (click)="handleFilter('grouped', true)">Grouped</li>
                <li class="filter-dropdown-item" nz-menu-item  (click)="handleFilter('grouped', false)">Ungrouped</li>
              </ul>
            </nz-dropdown>

TS

 activeFilter = {
    filterBy: 'Date',
    length: 100,
    status: 'ALL',
    order: 'ASC',
    grouped: false
  };

handleFilter(targetFilter?: string, value?: any) {
    this.activeFilter[targetFilter] = value;

    console.log(this.activeFilter);
    if (targetFilter === 'order') {
      // ?direction = 'asc' || 'desc']
    }
  }

如何使其多部分选择过滤?这是列表的示例:https ://i.stack.imgur.com/QJKAg.png

选择下拉菜单时应该有默认值Date->All->Ascending->Ungrouped

它应该是这样的 https://i.stack.imgur.com/GyEv1.png

4

1 回答 1

1

我在下面的链接中修改了代码

https://stackblitz.com/edit/angular-6zvbjl-uoffds

我为每个过滤器元素添加了条件图标

 <i nz-icon nzType="check" *ngIf="activeFilter.filterBy=='Application'" nzTheme="outline"></i>

在你的状态按钮中,我写了函数,因为它有两个以上的选项。对于其他人,我将条件放在 html 中

<a nz-dropdown nz-tooltip nzTitle="Feature not functional">
        {{ activeFilter.filterBy }} ->  {{ statuName(activeFilter.status) }} ->  {{ activeFilter.order=="ASC" ? "Ascending" : "Descending" }} ->  
        {{ activeFilter.grouped? "Groupped" : "Ungrouped" }}
      </a>

 statuName(param){
    if(param=="ALL"){return "All"}
    else if(param=="ACK"){return "Acknowledged"}
    else if(param=="READ"){return "Read"}
    else if(param=="NEW"){return "New"}
  }

对于您的分隔线,我将 css 代码与类名放在一起

.divider {
          height: 11px !important;
          margin: 4px 0;
          overflow: hidden;
          line-height: 0;
          background-color: #e8e8e887;
      }
于 2020-04-27T01:14:24.577 回答