Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda