Drag and drop Sortable table with elements added from JavaSc


Topic: Drag and drop Sortable table with elements added from JavaScript

Espen Rønning pro premium priority asked 3 months ago

Expected behavior I should be able to sort elements

Actual behavior Sorting is not working (sorry for the inadequate description, but please take a look at the code snippet and try to sort the elements...)

Resources (screenshots, code snippets etc.) https://mdbootstrap.com/snippets/standard/ererling-sande-no/6169653#html-tab-view


Grzegorz Bujański staff answered 3 months ago

Thanks for reporting. We'll fix it. Before we release a fixed version, you can first add elements to sortable-list and then init Sortable:

// Sortable
const sortableEl = document.getElementById('sortable');
for(i=1;i<=5;i++){
    const newElement = document.createElement('div');
    newElement.classList.add('sortable-item');
    newElement.textContent = 'New Element '+i; 
    sortableEl.append(newElement);
}
const instanceSortable = new DragAndDrop.Sortable(sortableEl);

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 7.3.2
  • Device: PC
  • Browser: Chrome
  • OS: Windows 11
  • Provided sample code: No
  • Provided link: Yes
Tags