import {OrderListModule} from 'primeng/orderlist';
OrderList requires an array as its value and a ng-template for its content where each item in the array can be accessed inside the ng-template using a local ng-template variable.
<p-orderList [value]="cars">
<ng-template let-car pTemplate="item">
<div class="ui-helper-clearfix">
<img src="assets/showcase/images/demo/car/{{car.brand}}.png" style="display:inline-block;margin:2px 0 2px 2px" width="48">
<div style="font-size:14px;float:right;margin:15px 5px 0 0">{{car.brand}} - {{car.year}} - {{car.color}}</div>
</div>
</ng-template>
</p-orderList>
export class MyComponent {
cars: Car[];
ngOnInit() {
this.cars = //initialize cars
}
}
Multiple items can either be selected using metaKey or toggled individually depending on the value of metaKeySelection property value which is true by default. On touch enabled devices metaKeySelection is turned off automatically.
Items can be filtered using an input field by enabling the filterBy property that specifies the fields to use in filtering.
<p-orderList [value]="cars" filterBy="brand"></p-orderList>
Multiple fields can be defines using a comma separates list.
<p-orderList [value]="cars" filterBy="brand,color,address.city"></p-orderList>
Items can be reordered using drag and drop by enabling dragdrop property along with dragdropScope to avoid conflict with other drag drop events on view.
<p-orderList [value]="cars" dragdrop="true" dragdropScope="cars">
In responsive mode, orderlist adjusts its controls based on screen size. To activate this mode, set responsive as true.
<p-orderList [value]="cars" [responsive]="true">
| Name | Type | Default | Description |
|---|---|---|---|
| value | array | null | An array of objects to reorder. |
| header | string | null | Text for the caption |
| style | string | null | Inline style of the component. |
| styleClass | string | null | Style class of the component. |
| listStyle | string | null | Inline style of the list element. |
| responsive | boolean | false | When enabled orderlist adjusts its controls based on screen size. |
| filterBy | string | null | When specified displays an input field to filter the items on keyup and decides which fields to search against. |
| metaKeySelection | boolean | true | When true metaKey needs to be pressed to select or unselect an item and when set to false selection of each item can be toggled individually. On touch enabled devices, metaKeySelection is turned off automatically. |
| dragdrop | boolean | false | Whether to enable dragdrop based reordering. |
| dragdropScope | string | null | Unique key of drag drop events to avoid conflict with other drag drop events on the page. |
| filterPlaceHolder | string | null | Placeholder text on filter input. |
| Name | Parameters | Description |
|---|---|---|
| onReorder | event: browser event | Callback to invoke when list is reordered. |
| onSelectionChange | originalEvent: browser event value: Current selection |
Callback to invoke when selection changes. |
| onFilterEvent | originalEvent: browser event value: Current filter values |
Callback to invoke when filtering occurs. |
Following is the list of structural style classes, for theming classes visit theming page.
| Name | Element |
|---|---|
| ui-orderlist | Container element. |
| ui-orderlist-list | List container. |
| ui-orderlist-item | An item in the list. |
None.
<p-orderList [value]="cars" [listStyle]="{'height':'250px'}" [responsive]="true" header="Cars"
filter="filter" filterBy="brand" filterPlaceholder="Filter by brand" dragdrop="true" dragdropScope="cars">
<ng-template let-car pTemplate="item">
<div class="ui-helper-clearfix">
<img src="assets/showcase/images/demo/car/{{car.brand}}.png" style="display:inline-block;margin:2px 0 2px 2px" width="48">
<div style="font-size:14px;float:right;margin:15px 5px 0 0">{{car.brand}} - {{car.year}} - {{car.color}}</div>
</div>
</ng-template>
</p-orderList>
export class OrderListDemo {
cars: Car[];
constructor(private carService: CarService) { }
ngOnInit() {
this.carService.getCarsSmall().then(cars => this.cars = cars);
}
}