OrderListOrderList is used to sort a collection. When the position of an item changes, the backend array is updated as well.

OrderList - 图1

Documentation

Import

  1. import {OrderListModule} from 'primeng/orderlist';
  2.  

Getting Started

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.

  1. <p-orderList [value]="cars">
  2. <ng-template let-car pTemplate="item">
  3. <div class="ui-helper-clearfix">
  4. <img src="assets/showcase/images/demo/car/{{car.brand}}.png" style="display:inline-block;margin:2px 0 2px 2px" width="48">
  5. <div style="font-size:14px;float:right;margin:15px 5px 0 0">{{car.brand}} - {{car.year}} - {{car.color}}</div>
  6. </div>
  7. </ng-template>
  8. </p-orderList>
  9.  
  1. export class MyComponent {
  2. cars: Car[];
  3. ngOnInit() {
  4. this.cars = //initialize cars
  5. }
  6. }
  7.  

Multiple Selection

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.

Selection Binding

The optional selection property is provided in case you'd like to a two-way binding to the selections.

  1. <p-orderList [value]="cars" [(selection)]="selectedCars">
  2. <ng-template let-car pTemplate="item">
  3. <div class="ui-helper-clearfix">
  4. <img src="assets/showcase/images/demo/car/{{car.brand}}.png" style="display:inline-block;margin:2px 0 2px 2px" width="48">
  5. <div style="font-size:14px;float:right;margin:15px 5px 0 0">{{car.brand}} - {{car.year}} - {{car.color}}</div>
  6. </div>
  7. </ng-template>
  8. </p-orderList>
  9.  
  1. export class MyComponent {
  2. cars: Car[];
  3. selectedCars: Car[];
  4. ngOnInit() {
  5. this.cars = //initialize cars
  6. }
  7. }
  8.  

Filtering

Items can be filtered using an input field by enabling the filterBy property that specifies the fields to use in filtering.

  1. <p-orderList [value]="cars" filterBy="brand"></p-orderList>
  2.  

Multiple fields can be defines using a comma separates list.

  1. <p-orderList [value]="cars" filterBy="brand,color,address.city"></p-orderList>
  2.  

DragDrop

Items can be reordered using drag and drop by enabling dragdrop property.

  1. <p-orderList [value]="cars" dragdrop="true">
  2.  

Buttons Location

Buttons that control the ordering are displayed at the left side of the list by default, controlsPosition property enables customizing the location. Currently right is the available alternative.

  1. <p-orderList [value]="cars" controlsPosition="right">
  2.  

Properties

NameTypeDefaultDescription
valuearraynullAn array of objects to reorder.
selectionarraynullAn array of objects to bind the selections.
headerstringnullText for the caption
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
listStylestringnullInline style of the list element.
filterBystringnullWhen specified displays an input field to filter the items on keyup and decides which fields to search against.
metaKeySelectionbooleantrueWhen 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.
dragdropbooleanfalseWhether to enable dragdrop based reordering.
filterPlaceHolderstringnullPlaceholder text on filter input.
trackByFunctionnullFunction to optimize the dom operations by delegating to ngForTrackBy, default algoritm checks for object identity.
controlsPositionstringleftDefines the location of the buttons with respect to the list, valid values are "left" or "right".
ariaFilterLabelstringnullDefines a string that labels the filter input.

Events

NameParametersDescription
onReorderevent: browser eventCallback to invoke when list is reordered.
onSelectionChangeoriginalEvent: browser event value: Current selectionCallback to invoke when selection changes.
onFilterEventoriginalEvent: browser event value: Current filter valuesCallback to invoke when filtering occurs.

Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
ui-orderlistContainer element.
ui-orderlist-listList container.
ui-orderlist-itemAn item in the list.

Dependencies

None.

Source

View on GitHub

  1. <p-orderList [value]="cars" [listStyle]="{'height':'250px'}" header="Cars"
  2. filter="filter" filterBy="brand" filterPlaceholder="Filter by brand" dragdrop="true">
  3. <ng-template let-car pTemplate="item">
  4. <div class="ui-helper-clearfix">
  5. <img src="assets/showcase/images/demo/car/{{car.brand}}.png" style="display:inline-block;margin:2px 0 2px 2px" width="48">
  6. <div style="font-size:14px;float:right;margin:15px 5px 0 0">{{car.brand}} - {{car.year}} - {{car.color}}</div>
  7. </div>
  8. </ng-template>
  9. </p-orderList>
  10.  
  1. export class OrderListDemo {
  2. cars: Car[];
  3. constructor(private carService: CarService) { }
  4. ngOnInit() {
  5. this.carService.getCarsSmall().then(cars => this.cars = cars);
  6. }
  7. }
  8.