Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何以角度过滤表(使用管道比较转换的数据)?_Javascript_Angular_Filter_Html Table_Ng Bootstrap - Fatal编程技术网

Javascript 如何以角度过滤表(使用管道比较转换的数据)?

Javascript 如何以角度过滤表(使用管道比较转换的数据)?,javascript,angular,filter,html-table,ng-bootstrap,Javascript,Angular,Filter,Html Table,Ng Bootstrap,我正在尝试使用搜索框和自定义管道以角度过滤表。 表中使用管道显示了一些值,如: {{order.tot | currency: 'EUR':'symbol':'.2-2':'it' }} {{order.datePayment | date: 'dd/MM/yyyy hh:mm:ss' }} 此处显示自定义管道: export class SearchFilterOrdersPipe implements PipeTransform { transform(orders, searc

我正在尝试使用搜索框和自定义管道以角度过滤表。 表中使用管道显示了一些值,如:

 {{order.tot | currency: 'EUR':'symbol':'.2-2':'it' }}
 {{order.datePayment | date: 'dd/MM/yyyy hh:mm:ss' }}
此处显示自定义管道:

export class SearchFilterOrdersPipe implements PipeTransform {

  transform(orders, searchValue: string): unknown {

    if (!orders || !searchValue) {
      return orders;
    }

    searchValue = searchValue.toLocaleLowerCase();
    return orders.filter(order =>
      order.idOrder.toString().includes(searchValue) ||
      order.email.toLocaleLowerCase().includes(searchValue) ||
      order.invoice.toLocaleLowerCase().includes(searchValue) ||
        //  order.datePayment.toString().includes(searchValue) ||
      order.paypalPaymentId.toLocaleLowerCase().includes(searchValue) ||
        //  order.tot.toString().includes(searchValue) ||
      order.status.includes(searchValue)
    )
  }
}
对于表中的所有字符串值,我没有任何问题。但“tot”和“datePayment”最初的格式是:

  • 订单日期付款日期:2021-01-13T09:27:11.000Z
  • 订单总数:100或15.50或20
因此,我永远不会捕捉到正确的值(例如,如果我搜索数据'17/01/2021'或tot,如15,50)

在.includes()之前的管道“datePayment”和“tot”中是否也有转换的方法


THX.

html中的管道仅用于显示,因此您无法在管道中访问它。可以注入管道并再次转换它们:

export class SearchFilterOrdersPipe implements PipeTransform {

  constructor(private date: DatePipe, private curreny: CurrencyPipe) {
  }

  transform(orders, searchValue: string): unknown {
    if (!orders || !searchValue) {
      return orders;
    }

    searchValue = searchValue.toLocaleLowerCase();
    return orders.filter(order =>
      this.date.transform(order.datePayment, 'dd/MM/yyyy hh:mm:ss').includes(searchValue) ||
      this.currency.transform(order.tot, 'EUR', 'symbol', '.2-2', 'it').includes(searchValue) ||
      ...
    )
  }
}

Thx@Felix,它可以工作,但我还必须在app.module.ts中添加“提供者”DatePipe和CurrencyPipe(可能对其他人有帮助)