Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7525709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:37:38+00:00 2026-05-30T03:37:38+00:00

I have successfully implemented JQuery Sortable. I can also write it to the database

  • 0

I have successfully implemented JQuery Sortable. I can also write it to the database using a separate call. However this only works for the first set of matching classes that are affected. The second, and I presume subsequent if there were any, don’t work.

<ul class="grouped-articles-list">
      <li id="4weight10"></li>
      <li id="3weight20"></li>
      <li id="2weight30"></li>
</ul>

<ul class="grouped-articles-list>
      <li id="5weight50"></li>
      <li id="6weight60"></li>    
      <li id="22weight70"></li>
      <li id="18weight80"></li>     
</ul>

I have multiple ULs that all share a common Class. The visual side all works correctly with them being fully sortable. I then write the objects to an array, Array = $(“.grouped-articles-list”).sortable(‘toArray’) and then call an ajax function. If I do a trace/console.log it only ever returns the objects of the previous (1st) class.

Is it possible to use Classes for multiple occasions and still be able to use the ToArray? In this instance if I were affecting the 2nd UL and did a trace it would still return [“4weight10”, “3weight20”, “2weight30”].

I will paste my code below, but It is a little verbose…

function makeSortable(){
    var before;
    var weight; 
    var newWeight = [];
    var newID = [];

    $(".grouped-articles-list").sortable({
        tolerance: 'pointer',   
        items: "li:not(.sortable_disabled)",
        start: function(event, ui){
            newWeight.length = 0;
            var resultbefore = $(".grouped-articles-list").sortable('toArray');
            before = resultbefore;
            //goes through each item and saves their weight to an array
            $.each(before, function(i) { 
            newWeight.push(splitWeightFromId(before[i])[3]);               
            });
        },
        stop: function(event, ui) {
            newID.length = 0;
            var after = $(".grouped-articles-list").sortable('toArray');
            $.each(after, function(i) { 
            //goes through each item in the array and saves out their id  
            newID.push(splitWeightFromId(after[i])[1]);
            // Only adds changed items
            if (newID[i] !== splitWeightFromId(before[i])[1]){
            //as the items move, but the weights stay the same
            //sends the affected ID with the always stationary weight off
               change_weight( newID[i], newWeight[i] )
        }     
    });
});

Ajax Function

function change_weight( link_id, new_weight ) { 
  $.ajax({
        type: "PUT",
        url:    "/article_relationships/" + link_id,
        data: {article_relationship : {
                                    weight : new_weight
                                    } },
        datatype: "js",
        remote: "true"
      });
}

Thank you for your time,

Any hints, tips or suggestions are more than welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:37:39+00:00Added an answer on May 30, 2026 at 3:37 am

    I managed to fix this, could be a better way but creating an array and going through it for each item worked fine.

    sortableArray = ($('.grouped-articles-list'));
        $(sortableArray).each(function(index){
        $(sortableArray[index]).sortable({
            tolerance: 'pointer', 
            items: "li:not(.sortable_disabled)", 
            start: function(event, ui){ 
              newWeight.length = 0; var resultbefore = $(sortableArray[index]).sortable('toArray');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully implemented Autocomplete field from database using sfWidgetFormJQueryAutocompleter but i cannot a
I am using a counter plugin for jquery (http://wplayground.comuv.com/counter/) and have it implemented successfully
I have implemented successfully this code: Does anyone know how to write an Apple
I have successfully implemented a working UIScrollView layer on top of Cocos2d using this
I have successfully implemented printing and print preview for my app using the PrintDocument,
On my new customer page , I have successfully implemented a jQuery show/hide toggle
I'm a complete noob to jquery and jquery ui but have successfully implemented a
I have a page in which i can successfully use the jquery focus function
I have successfully implemented a standard WCF service bound to MSMQ using the net.msmq
I have successfully implemented a UITextField in a UITableViewCell. Just like this: . I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.