Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving the order in the database #548

Open
iroshiva opened this issue Jul 5, 2020 · 1 comment
Open

Saving the order in the database #548

iroshiva opened this issue Jul 5, 2020 · 1 comment

Comments

@iroshiva
Copy link

iroshiva commented Jul 5, 2020

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

@EddiesTech
Copy link

EddiesTech commented Feb 5, 2023

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants