The Ionic offers the <ion-reorder> component to reordering features. Ionic reorder component adds the Drag and Drop feature to list items, in which the user can change the order of the items. Reorder can be used within the <ion-list> and <ion-item-group> to offer a visual drag and drop interface in the item list. The <ion-reader> is the anchor component used to drag and drop the items within the <ion-reorder-group> component.

When the user drags and drops the list of the items to the new position, then the ionItemReorder event is dispatched. The handler for the ion-reorder should be implemented, which calls the complete() method. The ionItemReorder event contains a different property that includes all the valid information about the reorder operation. It consists of the form and to indexes. In the case of reordering, the item moves from an index to a new index.

There are many functionalities of such sorting or reorder found in many places such as Song Ques, Todo list items, etc.

Example: This example explains how you can use the reorder component in the ionic application. It allows the user to drag and drop the items to a new position. Here, you are going to update the list items by calling the complete() method.

This file contains the list items inside the <ion-reorder-group> component, which have an iteration of items array using angular *ngFor directive. In the <Ion-reorder-group> component, you have to set the disabled property at false, which enables the drag and drop feature in the ionic application. The ionItemReorder is that event, which enables them to complete the reordering of the items.

This file contains the implementation of the onRenderItems($event). It contains the index list from to the item dragged. By using the splice() method, you can remove and drag the item from top to bottom and bottom to up an array and assigns it to the variable draggedItem. Also that, it calls the complete() method to complete the reorder operation.

Output: After executing this code, you will get the output, as shown below:

Ionic Reorder

When you dragged any item from the list and dropped it to the new position, which is shown below:

Ionic Reorder2

Pin It on Pinterest

Share This