Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sortablejs

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sortablejs

JavaScript library for reorderable drag-and-drop lists on modern browsers and touch devices. No jQuery required. Supports Meteor, AngularJS, React, Polymer, Vue, Knockout and any CSS library, e.g. Bootstrap.

  • 1.15.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is sortablejs?

The sortablejs package is a JavaScript library for creating reorderable drag-and-drop lists on modern web browsers and touch devices. It does not require any jQuery dependency and provides a simple API for developers to enable sortable functionality in their web applications.

What are sortablejs's main functionalities?

Basic list sorting

This code snippet enables drag-and-drop sorting on the list with the ID 'items'. It creates a Sortable instance that allows list items to be reordered by dragging.

var el = document.getElementById('items');
var sortable = Sortable.create(el);

Grouping and sharing between lists

This code snippet connects two lists, allowing items to be dragged from one list to another. Both lists share the same 'group' property, enabling the sharing of items.

var el1 = document.getElementById('list1');
var el2 = document.getElementById('list2');
Sortable.create(el1, {
  group: 'shared',
  animation: 150
});
Sortable.create(el2, {
  group: 'shared',
  animation: 150
});

Saving and restoring list order

This code snippet demonstrates how to save the order of the list to localStorage and restore it when the page is reloaded. The 'store' option is used to provide custom 'get' and 'set' functions for storing the order.

var el = document.getElementById('items');
var sortable = Sortable.create(el, {
  store: {
    get: function (sortable) {
      var order = localStorage.getItem(sortable.options.group.name);
      return order ? order.split('|') : [];
    },
    set: function (sortable) {
      var order = sortable.toArray();
      localStorage.setItem(sortable.options.group.name, order.join('|'));
    }
  }
});

Customizing drag handle

This code snippet shows how to specify a custom drag handle for list items. Only elements with the class 'my-handle' will be draggable.

var el = document.getElementById('items');
var sortable = Sortable.create(el, {
  handle: '.my-handle',
  animation: 150
});

Other packages similar to sortablejs

Keywords

FAQs

Package last updated on 28 Nov 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc