Socket
Socket
Sign inDemoInstall

ngx-virtual-dnd-list

Package Overview
Dependencies
6
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ngx-virtual-dnd-list

A virtual scrolling list component that can be sorted by dragging


Version published
Weekly downloads
3
decreased by-50%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

ngx-virtual-dnd-list

npm npm Software License

A virtual scrolling list component that can be sorted by dragging

Live demo

Simple usage

npm i ngx-virtual-dnd-list

virutal-list.module.ts

...
import { VirtualDndListModule } from 'ngx-virtual-dnd-list';

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

virutal-list.component.ts

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

@Component({
  selector: 'virutal-list',
  template: `
    <div #scroller>
      <virtual-dnd-list
        [scroller]="scroller"
        [dataKey]="'id'"
        [keeps]="30"
        [(ngModel)]="list"
        (ngModelChange)="onChange($event)"
      >
        <ng-template let-data let-index>
          <span>{{ data.index }}</span>
          <p>{{ data.id }}</p>
        </ng-template>
      </virtual-dnd-list>
    </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
onBottomscrolled to bottom
onDragthe drag is started
onDropthe drag is completed

Attributes

Required Attributes

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

Optional Attributes

Commonly used

PropTypeDefaultDescription
keepsNumber30The number of lines rendered by the virtual scroll
sizeNumber-The estimated height of each piece of data, you can choose to pass it or not, 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 }
keepOffsetBooleanfalseWhen scrolling up to load data, keep the same offset as the previous scroll
directionvertical | horizontalscroll direction
lockAxisx | y-Axis on which dragging will be locked
debounceTimeNumber0debounce time on scroll
throttleTimeNumber0throttle time on scroll

Uncommonly used

PropTypeDefaultDescription
draggableString-Specifies which items inside the element should be draggable. If does not set a value, the default list element can be dragged
sortableBooleantrueAllow Sorting by Dragging
disabledBooleanfalseDisables the sortable if set to true
animationNumber150Animation speed moving items when sorting
autoScrollBooleantrueAutomatic scrolling when moving to the edge of the container
scrollThresholdNumber55Threshold to trigger autoscroll
delayNumber0Time in milliseconds to define when the sorting should start
delayOnTouchOnlyBooleanfalseOnly delay on press if user is using touch
fallbackOnBodyBooleanfalseAppends the ghost element into the document's body
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

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
scrollToIndex(index)Scroll to the specified index position
scrollToOffset(offset)Scroll to the specified offset

Usage

import { Component, ViewChild } from '@angular/core';
import { VirtualDndListComponent } from 'ngx-virtual-dnd-list';

@Component({
  selector: 'virutal-list',
  template: `
    <div #scroller>
      <virtual-dnd-list
        #virtualList
        ...
      >
        ...
      </virtual-dnd-list>

      <button (click)="scrollToBottom()">scroll to bottom</button>
    </div>
  `,
  styles: [],
})
export class VirtualListComponent {
  @ViewChild('virtualList') virtualList: VirtualDndListComponent;

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

Keywords

FAQs

Last updated on 24 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc