简体   繁体   English

如何在PrimeNG中使用RowGroup交换组位置?

[英]How to swap groups position using RowGroup in PrimeNG?

I'm trying to swap groups but not having any luck. 我正在尝试交换组,但没有任何运气。 Basically I have to group them in this order: 基本上,我必须按以下顺序将它们分组:

ROOM3
 - Yoga, Martha   busy-3
 - Bacon, Anna    busy-3
   .........
   ...............
ROOM1
 - Brady, Marsha     busy
 - McDonald, Jane    busy
 ...............
 ....................
ROOM2 
 - Steve, Ana      busy-2
 - tester          busy-2
 .........
 ...............

In simple words I want to keep the order of the grouping like this: 用简单的话来说,我想保持这样的分组顺序:

ROOM3 --> ROOM1 --> ROOM2 房间3->房间1->房间2

Here's my working code: 这是我的工作代码:

PLUNKER PLUNKER

There might be a better solution but if you add a roomOrderId to each row of your data object, then you can sort by this field : 也许会有更好的解决方案,但是如果您向data对象的每一行添加一个roomOrderId ,则可以按以下字段进行排序:

sortField="roomOrderId"

Edit You can manually add roomOrderId to each row : 编辑您可以手动将roomOrderId添加到每一行:

    this.data.forEach(function(row) {
      if(row.room==="ROOM1") {
        row.roomOrderId = 2;
      } else if(row.room==="ROOM2") {
        row.roomOrderId = 3;
      } else if(row.room==="ROOM3") {
        row.roomOrderId = 1;
      }
    });

See my Plunker 见我的柱塞

i added extra pos field in data object: 我在数据对象中添加了额外的pos字段:

data = [
    { box: '',  name: 'Brady, Marsha', status: 'busy', room: 'ROOM1' ,pos:2},
    { box: '1', name: 'Davis, Kevin', status: 'busy-1' , room: 'ROOM1',pos:2},
    { box: '1', name: 'Carter, Dawn',  status: 'busy-1' , room: 'ROOM1',pos:2},
    { box: '',  name: 'McDonald, Jane',status: 'busy', room: 'ROOM1',pos:2 },
    { box: 'MA',name: 'Bacon, Anna', status: 'wbusy-3', room: 'ROOM3',pos:1 },
    { box: 'MA',name: 'Yoga, Martha', status: 'busy-3', room: 'ROOM3' ,pos:1},
    { box: '1', name: 'Steve, Ana', status: 'busy-2', room: 'ROOM2',pos:3},
    { box: '2', name: 'tester', status: '', room: 'ROOM2',pos:3},
    { box: '3', name: 'Jhonson, Francisco', status: 'busy-2' , room: 'ROOM2',pos:3},
    { box: '4', name: 'Mathews, Susan', status: 'busy-2' , room: 'ROOM2',pos:3},
    { box: '5', name: 'Davis, Christine', status: 'busy-2' , room: 'ROOM2',pos:3},
    { box: '6', name: 'Wheaters, Bob', status: 'busy-2' , room: 'ROOM2',pos:3},
    { box: '7', name: 'Kinsky, Annabelle' , status: 'busy-2' , room: 'ROOM2',pos:3},
    { box: '8', name: '', status: '', room: 'ROOM2',pos:3},
    { box: '9', name: 'Stephanapolous', status: 'busy-2' , room: 'ROOM2',pos:3},
    { box: '10',name: 'Kelley, Tom', status: 'busy-2' , room: 'ROOM2',pos:3},
    { box: 'T', name: 'Peterson, James', status: 'busy-2' , room: 'ROOM2',pos:3}
]

and in html : 并在html中:

<p-dataTable [value]="data" sortField="room" rowGroupMode="subheader" groupField="room" expandableRowGroups="true"
        [sortableRowGroup]="false" sortField="pos" sortOrder="1">
    <ng-template pTemplate="rowgroupheader" let-rowData>{{rowData.room}} - INFO</ng-template>
    <p-column field="status" header="ID"></p-column>
    <p-column field="name" header="Title"></p-column>

</p-dataTable>

which will sort in your given order. 它将按照您给定的顺序排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM