maykinmedia / dual-listbox

A simple dual listbox build in plain Javascript and some simple styling. (no other libraries of frameworks required)
https://maykinmedia.github.io/dual-listbox/
MIT License
104 stars 43 forks source link

Sorting problem to php array #58

Open shoniax opened 3 years ago

shoniax commented 3 years ago

Hello , when I change order of selected items I got random sort when i try to print it.

image

Here is the result image

haught commented 3 years ago

I have the same problem, the user defined order is not preserved into the form submittal - it will always be the same order as the original left sided options.

steveerg commented 3 years ago

Same problem here ... left side options order rules on the right side.

ataknakbulut commented 2 years ago

Same problem here

erenilhan commented 2 years ago

+1

arnofo commented 1 year ago

I encounter the same problem but only on Chrome. It works fine with Firefox.

I have run a few tests and it seems to come down to the browser sorting algorithm, maybe related to this explanation ?

https://stackoverflow.com/a/44120478

ducvu91 commented 11 months ago

I checked it run in here https://preview.keenthemes.com/metronic/demo9/features/miscellaneous/dual-listbox.html anyone have solution ?

ssada1975 commented 1 month ago

_initializeSortButtons() { let t = document.createElement("button"); t.classList.add("dual-listbox__button"), t.innerText = this.upButtonText, t.addEventListener("click", i => this._onSortButtonClick(i, h, 'selected')); let e = document.createElement("button"); e.classList.add("dual-listbox__button"), e.innerText = this.downButtonText, e.addEventListener("click", i => this._onSortButtonClick(i, u, 'selected')); let s = document.createElement("div"); s.classList.add("dual-listbox_sortButtons"), s.appendChild(t), s.appendChild(e), this.selectedListTitle.appendChild(s)

            t = document.createElement("button");
            t.classList.add("dual-listbox__button"), t.innerText = this.upButtonText, t.addEventListener("click", i => this._onSortButtonClick(i, h, 'available'));
            e = document.createElement("button");
            e.classList.add("dual-listbox__button"), e.innerText = this.downButtonText, e.addEventListener("click", i => this._onSortButtonClick(i, u, 'available'));
            s = document.createElement("div");
            s.classList.add("dual-listbox_sortButtons"), s.appendChild(t), s.appendChild(e), this.availableListTitle.appendChild(s)

        }

_onSortButtonClick(t, e, as) { t.preventDefault(); let list = this.dualListbox.querySelector(".dual-listbox__"+as); let orderedLIs = [...list.children].sort((a, b) => a.textContent.localeCompare(b.textContent) ); if (e=="down") orderedLIs = orderedLIs.reverse(); list.innerHTML = orderedLIs.map(li => li.outerHTML).join(''); }