Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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
Angular 无两列(或更多列)以素数突出显示的多列排序_Angular_Sorting_Primeng - Fatal编程技术网

Angular 无两列(或更多列)以素数突出显示的多列排序

Angular 无两列(或更多列)以素数突出显示的多列排序,angular,sorting,primeng,Angular,Sorting,Primeng,我可以在使用带素数的p-table时对多个列进行排序,如下所示: [multiSortMeta]="[{field: 'quantity', order: -1}, {field: 'price', order: 1}]" 多排序列 {{col.header}} {{rowData[col.field]} 然而,在默认情况下突出显示两列可能会令人困惑。如何对两列进行默认排序,而只突出显示主列?假设您希望按数量和价格对数据进行排序,但只在表中显示数量指标 首先,按pric

我可以在使用带素数的
p-table
时对多个列进行排序,如下所示:

[multiSortMeta]="[{field: 'quantity', order: -1}, {field: 'price', order: 1}]"

多排序列
{{col.header}}
{{rowData[col.field]}

然而,在默认情况下突出显示两列可能会令人困惑。如何对两列进行默认排序,而只突出显示主列?

假设您希望按
数量
价格
对数据进行排序,但只在表中显示
数量
指标

首先,按
price
对服务返回的数据进行排序:

this.productService.getProductsSmall().then(data => {
  this.products2 = data.sort((a, b) => a.price - b.price);
});
或者,如果您想要相反的顺序:

this.productService.getProductsSmall().then(data => {
  this.products2 = data.sort((a, b) => b.price - a.price);
});
然后,替换

[multiSortMeta]="[{field: 'quantity', order: -1}, {field: 'price', order: 1}]"

仅显示
数量
指示器

它应该符合你的需要


从我的理解来看,我相信,没有js,没有其他方法可以做到这一点。我确实不这么认为。。。
[multiSortMeta]="[{field: 'quantity', order: -1}, {field: 'price', order: 1}]"
[multiSortMeta]="[{field: 'quantity', order: -1}]"