Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

213
Vistas
Sortable.js mismatched naming convention to child elements

I'm working on a WordPress website and I want the user to have the ability to reorder the sidebar widgets even if the site reloads.

So I'm using Sortable JS and using the saving and restoring of the sort as I plan to store it in localStorage but I couldn't make it work. It's pretty straightforward in the documentation and the demo but for some reason, it's not working for me and I'm not sure what I'm missing.

Below is the default sorting of the elements.

enter image description here

And once I reorder these widgets, I get this result.

enter image description here

I believe the issue was the naming of the keys is incorrect. See the highlighted text with blue in the image below. It's missing in the array called from the set method.

enter image description here

So the highlighted with blue here is the log from the get: function (sortable) method and the array output is from the set: function (sortable) .

Here's a quick video to see it more clearly.

Below is my code.

let el = document.getElementById('sticky-sidebar');

Sortable.create(el, {
    group: 'foo',
    animation: 100,
    draggable: ".widget_block",
    store: {
        /**
                 * Get the order of elements. Called once during initialization.
                 * @param   {Sortable}  sortable
                 * @returns {Array}
                 */
        get: function (sortable) {
        var order = localStorage.getItem(sortable.options.group.name);
        console.log(order)
        return order ? order.split('|') : [];
        },
    
        /**
                 * Save the order of elements. Called onEnd (when the item is dropped).
                 * @param {Sortable}  sortable
                 */
        set: function (sortable) {
        var order = sortable.toArray();
        console.log(order)
        localStorage.setItem(sortable.options.group.name, order.join('|'));
        }
    }
});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda