Vue Draggable Virtual Scroll List

0.0.15 · active · verified Sun Apr 19

This `vue-draggable-virtual-scroll-list` package is a Vue 2 component designed to combine the drag-and-drop capabilities of `SortableJS/Vue.Draggable` with the performance benefits of `tangbc/vue-virtual-scroll-list` for rendering large datasets. It allows developers to create sortable lists that efficiently handle a significant number of items by only rendering the visible elements, while still supporting intuitive drag-and-drop interactions. Currently at version 0.0.15, the project appears to be in an early development phase, suggesting potential for rapid changes. Its primary differentiation lies in offering a pre-integrated solution for two common UI challenges in Vue 2: managing large lists and enabling sortability, bypassing the need for manual integration of these complex libraries. It explicitly lists Vue 2.6.14 or higher as a peer dependency, firmly placing it within the Vue 2 ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to set up `DraggableVirtualList` in a Vue 2 application, providing a sortable, virtualized list of 1000 items. It shows how to pass data, configure item height, and specify the individual item component.

import Vue from 'vue';
import { DraggableVirtualList } from 'vue-draggable-virtual-scroll-list';

// Define the individual item component
const Item = {
  props: {
    source: {
      type: Object,
      default: () => ({}),
    },
  },
  template: `
    <div class="phrase" :key="source.id" style="padding: 10px; border-bottom: 1px solid #eee; background-color: white;">
      {{ source.content }}
    </div>
  `,
};

new Vue({
  el: '#app',
  components: {
    DraggableVirtualList,
  },
  data() {
    const items = [];
    // Generate a large number of items for virtualization demo
    for (let i = 0; i < 1000; i++) {
      items.push({
        id: i,
        content: `Item ${i + 1} - Drag me!`, // Example content
      });
    }
    return {
      items: items,
      Item: Item, // Pass the local Item component to the DraggableVirtualList
    };
  },
  template: `
    <div id="app">
      <h2>Draggable Virtual List Example</h2>
      <p>Drag and drop items in this list. It efficiently handles 1000 items.</p>
      <draggable-virtual-list
        class="phrase-list"
        v-model="items"
        :size="50"           // Estimated height of each item in pixels
        :keeps="20"          // Number of items to keep rendered outside the viewport
        :data-key="'id'"     // Unique key for each item in the data source
        :data-sources="items" // Data source for the virtual list
        :data-component="Item" // Component to render each item
        style="height: 400px; overflow-y: auto; border: 1px solid #ccc;"
      >
      </draggable-virtual-list>
    </div>
  `,
});

view raw JSON →