JSPM

  • Created
  • Published
  • Downloads 688
  • Score
    100M100P100Q108266F
  • License ISC

A virtual scrolling list component that can be sorted by dragging , for Vue

Package Exports

  • vue-virtual-draglist
  • vue-virtual-draglist/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vue-virtual-draglist) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Downloads Version

A virtual scrolling list component that can be sorted by dragging , for Vue

Simple usage

npm i vue-virtual-draglist -D

Root component:

<template>
  <div>
    <virtual-drag-list
      :data-key="'id'"
      :data-source="list"
      @top="handleToTop"
      @bottom="handleToBottom"
      @ondragend="ondragend"
    >
      <template slot="item" slot-scope="{ record, index, dataKey }">
        <span draggable="true">{{ record.id }}</span>
        {{ record.text }}
      </template>
      <template slot="header">
        <div class="loading">top loading...</div>
      </template>
      <template slot="footer">
        <div class="loading">bottom loading...</div>
      </template>
    </virtual-drag-list>
  </div>
</template>

<script>
  import virtualDragList from 'vue-virtual-draglist'

  export default {
    name: 'root',
    data () {
      return {
        list: [{id: '1', text: 'asd'}, {id: '2', text: 'fgh'}, ...]
      }
    },
    components: { virtualDragList },
    methods: {
      handleToTop() {
        ...
      },
      handleToBottom() {
        ...
      },
      ondragend(list) {
        console.log(list)
      }
    }
  }
</script>

Emits

emit Description
top event fired when scroll to top
bottom event fired when scroll to bottom
ondragend event fired when the drag is complete, return a new array

Props type

Required props

Prop Type Description
data-key String The unique identifier of each piece of data, in the form of 'a.b.c'
data-source Array data list

Optional props

Commonly used

Prop Type Default Description
keeps Number 30 the number of lines rendered by the virtual scroll
size Number 50 The estimated height of each piece of data, you can choose to pass it or not, it will be automatically calculated
draggable Boolean true whether to support drag and drop. You need to specify a draggable element and set the `draggable` attribute for it
Uncommonly used

Prop Type Default Description
delay Number 10 Delay time of debounce function
dragElement Function - The function that selects the dragged element, must have a return value with a dom node, has two parameters: e(the currently selected element), parent(the parent node of the list)
headerTag String div Label type for header slot
footerTag String div Label type for footer slot
itemTag String div item's tag type
itemStyle Object {} item's style
itemClass String '' item's class
dragStyle Object {} mask style when dragging

Public methods

Usefull public methods

Use ref to get the method inside the component

Method Description
scrollToBottom() scroll to bottom of list
scrollToTop() scroll to top of list
scrollToIndex(index) scroll to the specified index position
scrollToOffset(offset) scroll to the specified height
getSize(dataKey) get the height of the current item by unique key value
getOffset() get the current scroll height
reset() reset to initial