ngx-virtual-sortable

June 9, 2026 ยท View on GitHub

npm npm Software License

A virtual scrolling list component that can be sorted by dragging

Live demo

Simple usage

npm i ngx-virtual-sortable

virutal-list.module.ts

...
import { VirtualListModule } from 'ngx-virtual-sortable';

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...
    VirtualListModule
  ],
  providers: []
})
export class ListModule { }

virutal-list.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'virutal-list',
  template: `
    <div #scroller>
      <div
        virtual-list
        [scroller]="scroller"
        [dataKey]="'id'"
        [keeps]="30"
        [(ngModel)]="list"
        (ngModelChange)="onChange($event)"
      >
        <ng-template let-item let-index="index">
          <div class="list-item">
            <span>{{ index }}</span>
            <p>{{ item.text }}</p>
          </div>
        </ng-template>
      </div>
    </div>
  `,
  styles: [],
})
export class AppComponent {
  public list = [
    { id: 'a', text: 'aaa' },
    { id: 'b', text: 'bbb' },
    { id: 'c', text: 'ccc' },
    ...
  ];

  onChange(data) {
    // the data changes after the dragging ends
  }
}

EventEmitters

EventDescription
onTopScrolled to top of scroll element
onBottomScrolled to bottom of scroll element
onScrollScroll event
onDragElement dragging started
onDropElement dragging is completed
onRangeChangeList rendering range changed

Props

Required Props

PropTypeDescription
data-keyStringThe unique identifier of each piece of data, in the form of 'a.b.c'
scrollerHTMLElement | DocumentVirtual list scrolling element

Optional Props

Commonly used

PropTypeDefaultDescription
keepsNumber30The number of lines rendered by the virtual scroll
sizeNumber-The estimated height of each piece of data, it will be automatically calculated
handleFunction/String-Drag handle selector within list items
groupObject/String-string: 'name' or object: { name: 'group', put: true/false, pull: true/false/'clone', revertDrag: true/false }
directionvertical | horizontalscroll direction
lockAxisx | y-Axis on which dragging will be locked
tableModeBooleanfalseUsing Virtual Lists in Tabular Mode
keepOffsetBooleanfalseWhen scrolling up to load data, keep the same offset as the previous scroll
debounceTimeNumber0debounce time on scroll
throttleTimeNumber0throttle time on scroll

Uncommonly used

PropTypeDefaultDescription
wrapperHTMLElement-Virtual list wrapper
bufferNumberMath.round(keeps / 3)Buffer size to detect range change
sortableBooleantrueAllow Sorting by Dragging
draggableString[role="item"]Specifies which items inside the element should be draggable
disabledBooleanfalseDisables the sortable if set to true
animationNumber150Animation speed moving items when sorting
autoScrollBooleantrueAutomatic scrolling when moving to the edge of the container
scrollSpeedObject{ x: 10, y: 10}Vertical&Horizontal scrolling speed (px)
scrollThresholdNumber55Threshold to trigger autoscroll
delayNumber0Time in milliseconds to define when the sorting should start
delayOnTouchOnlyBooleanfalseOnly delay on press if user is using touch
appendToBodyBooleanfalseAppends the ghost element into the document's body
dropOnAnimationEndBooleantrueWhether to trigger the drop event when the animation ends
ghostClassString''The class of the mask element when dragging
ghostStyleObject{}The style of the mask element when dragging
chosenClassString''The class of the selected element when dragging
placeholderClassString''Class name for the drop placeholder

Public Methods

MethodDescription
getSize(key)Get the size of the current item by unique key value
getOffset()Get the current scroll height
getClientSize()Get wrapper element client viewport size (width or height)
getScrollSize()Get all scroll size (scrollHeight or scrollWidth)
scrollToTop()Scroll to top of list
scrollToBottom()Scroll to bottom of list
scrollToKey(key)Scroll to the specified data-key position
scrollToIndex(index, align)Scroll to the specified index position
scrollToOffset(offset, align)Scroll to the specified offset

Usage

import { Component, ViewChild } from '@angular/core';
import { VirtualListComponent } from 'ngx-virtual-sortable';

@Component({
  selector: 'virutal-list',
  template: `
    <div #scroller>
      <virtual-list
        #virtualList
        ...
      >
        ...
      </virtual-list>
    </div>
    <button (click)="scrollToBottom()">scroll to bottom</button>
  `,
  styles: [],
})
export class ListComponent {
  @ViewChild('virtualList') virtualList: VirtualListComponent;

  scrollToBottom() {
    this.virtualList.scrollToBottom();
  }
}