As of my knowledge cutoff date in September 2021, PrimeNG DataTable does not have built-in support for row reordering. However, you can achieve row reordering functionality with PrimeNG DataTable by implementing custom logic.

To enable row reordering in PrimeNG DataTable, you can follow these general steps:

  1. Add Drag and Drop Functionality: You can use PrimeNG's pDraggable and pDroppable directives to enable drag and drop functionality for the rows in the DataTable.

  2. Handle Drag and Drop Events: Implement logic to handle the drag and drop events, such as onDragStart, onDragEnter, onDragLeave, and onDrop, to track the source and destination of the dragged row.

  3. Update Data Array: Upon successful drop, update the data array of the DataTable to reflect the new order of the rows.

Here's a basic example of how you might approach implementing row reordering in PrimeNG DataTable:

  1. HTML Template:
<p-dataTable [value]="data" reorderableColumns="true"> <ng-template pTemplate="header"> <!-- Add column headers here --> </ng-template> <ng-template pTemplate="body" let-rowData let-rowIndex="rowIndex"> <tr pDraggable [pDragData]="rowData" (onDragStart)="onDragStart($event, rowIndex)"> <!-- Render the row data here --> </tr> </ng-template> </p-dataTable>
  1. Component Class:
import { Component } from '@angular/core'; @Component({ selector: 'app-my-component', templateUrl: './my-component.html', }) export class MyComponent { data: any[] = [/* Your data array here */]; draggingRow: any; draggingRowIndex: number; onDragStart(event: any, index: number): void { this.draggingRow =; this.draggingRowIndex = index; } onDrop(event: any): void { if (this.draggingRow && this.draggingRowIndex !== event.dropIndex) { const newData = []; newData.splice(this.draggingRowIndex, 1); newData.splice(event.dropIndex, 0, this.draggingRow); = newData; this.draggingRow = null; } } }

In this example, we use PrimeNG's pDraggable directive to enable drag functionality on the DataTable rows and pDroppable for the container that should receive the dropped row. The onDragStart method is called when the drag operation starts, and onDrop is called when the drag operation is completed.

Keep in mind that this is a basic example, and you may need to customize it to fit your specific use case and data structure. Additionally, since PrimeNG evolves over time, the availability of specific features might change in newer versions. Therefore, always refer to the official PrimeNG documentation and release notes for the latest features and updates related to DataTable and row reordering.

Have questions or queries?
Get in Touch