packery icon indicating copy to clipboard operation
packery copied to clipboard

Saving the order in the database

Open iroshiva opened this issue 5 years ago • 1 comments
trafficstars

Hi everybody,

Does anybody know how to save the position of the elements after dragging in the database with ajax (in a column position) ?

With an another configuration, i used :

 $(function() {
    $("container_with_all_images").sortable({
      update: function(e, ui){
        ui.placeholder.height(ui.item.height());
        Rails.ajax({
          url: $(this).data("url"),
          type: "PATCH",
          data: $(this).sortable('serialize')
        });
      }
    }).disableSelection();

  });

Thx !

Jean

iroshiva avatar Jul 05 '20 21:07 iroshiva

This is very so you have probably found a solution, but for the purposes of others finding the issue... Currently, I have a one-column grid. When the code/the user adds an element to the items div, I give it a name and add that name as an attribute "data-backendname" and other data. Then when the user presses save, I run this function, to get the elements and shove it in a json to send to the database

function getListofItems() {
    var items = []
    window.pckry.getItemElements().forEach((element)=>{
        if (typeof element.dataset != 'undefined' && typeof element.dataset.backendname != 'undefined') {
            if(element.dataset.backendname.startsWith("customlink-")){
                items.push({"custom": true, "backendname":element.dataset.backendname, "name":element.dataset.name, "description":element.dataset.description, "url":element.dataset.url})
            }else{
        items.push({"backendname": element.dataset.backendname, "custom":false})
            }
    }
    })
    return items
}

EddiesTech avatar Feb 05 '23 00:02 EddiesTech