admin管理员组

文章数量:1384752

I am trying to implement the multiselect in primeng table, Following I have tried

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './appponent.html',
  styleUrls: [ './appponent.css' ]
})
export class AppComponent  {

tableHeader= [
            { 'field': 'type', 'header': 'Type' },
            { 'field': 'value', 'header': 'Value' },
            ];

tableValue = [
    {'type':'A1','value':'row1'},
    {'type':'A1','value':'row2'},
    {'type':'A2','value':'row3'},
    {'type':'A2','value':'row4'},
    {'type':'A1','value':'row5'},
  ];

statusOptions = [
      { 'label': 'A1', 'value': 'A1' },
      { 'label': 'A2', 'value': 'A2' }
  ];

}

and html file is

<p-table [columns]="tableHeader" [value]="tableValue" [sortOrder]="1"
[responsive]="true" rowHover="true" [rowsPerPageOptions]="[5,10,25]" alwaysShowPaginator="false" [rows]="10"
sortMode="multiple" #tdv>
<ng-template pTemplate="header">
    <tr>
        <th *ngFor="let col of tableHeader" [pSortableColumn]="col.field">
            <span>{{col.header}}</span>
        </th>
    </tr>
    <tr>
        <th *ngFor="let col of tableHeader" [pSortableColumn]="col.field">
          <p-multiSelect [options]="statusOptions" *ngIf='col.field =="type"' (onChange)="tdv.filter($event.value,col.field,'equals')"></p-multiSelect>
        </th>

    </tr>
</ng-template>
  <ng-template pTemplate="body" let-row>
    <tr>
        <td>{{row.type}}</td>
        <td>{{row.value}}</td>
  </ng-template>
</p-table>

I am trying to filter the value with A1 and A2. But If I select the single value it is working but if I select the multiple value it is not working. I don't know how to fix this issue..

I am trying to implement the multiselect in primeng table, Following I have tried

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.ponent.html',
  styleUrls: [ './app.ponent.css' ]
})
export class AppComponent  {

tableHeader= [
            { 'field': 'type', 'header': 'Type' },
            { 'field': 'value', 'header': 'Value' },
            ];

tableValue = [
    {'type':'A1','value':'row1'},
    {'type':'A1','value':'row2'},
    {'type':'A2','value':'row3'},
    {'type':'A2','value':'row4'},
    {'type':'A1','value':'row5'},
  ];

statusOptions = [
      { 'label': 'A1', 'value': 'A1' },
      { 'label': 'A2', 'value': 'A2' }
  ];

}

and html file is

<p-table [columns]="tableHeader" [value]="tableValue" [sortOrder]="1"
[responsive]="true" rowHover="true" [rowsPerPageOptions]="[5,10,25]" alwaysShowPaginator="false" [rows]="10"
sortMode="multiple" #tdv>
<ng-template pTemplate="header">
    <tr>
        <th *ngFor="let col of tableHeader" [pSortableColumn]="col.field">
            <span>{{col.header}}</span>
        </th>
    </tr>
    <tr>
        <th *ngFor="let col of tableHeader" [pSortableColumn]="col.field">
          <p-multiSelect [options]="statusOptions" *ngIf='col.field =="type"' (onChange)="tdv.filter($event.value,col.field,'equals')"></p-multiSelect>
        </th>

    </tr>
</ng-template>
  <ng-template pTemplate="body" let-row>
    <tr>
        <td>{{row.type}}</td>
        <td>{{row.value}}</td>
  </ng-template>
</p-table>

I am trying to filter the value with A1 and A2. But If I select the single value it is working but if I select the multiple value it is not working. I don't know how to fix this issue..

Share Improve this question asked Apr 23, 2019 at 12:27 mkHunmkHun 5,9219 gold badges43 silver badges95 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

The mutlisect value when selecting A1 and A2 is "A1,A2" so you need to use in instead of equals:

 <p-multiSelect [options]="statusOptions" *ngIf='col.field =="type"' (onChange)="tdv.filter($event.value,col.field,'in')"></p-multiSelect>

本文标签: javascriptHow to use MultiSelect filter in PrimeNG tableStack Overflow