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 7586991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:33:47+00:00 2026-05-30T19:33:47+00:00

I am using jQuery UI sortable plugin to manage the weight values of my

  • 0

I am using jQuery UI sortable plugin to manage the weight values of my data in my database. Out of the box, the jQuery sortable serialization will return all of the data indexes in the list to be updated. This is unnecessary for me since the only items that have a weight change on update are those between the the new index of the item and the previous index (or vice versa).

For example, lets look at the following dataset:

<div id="sortable">
    <div id="data_A">Data A</div>
    <div id="data_B">Data B</div>
    <div id="data_C">Data C</div>
    <div id="data_D">Data D</div>
    <div id="data_E">Data E</div>
    <div id="data_F">Data F</div>
</div>

[0] = A
[1] = B
[2] = C
[3] = D
[4] = E
[5] = F

If I move D to position 1 in the list, we now have the following:

<div id="sortable">
    <div id="data_A">Data A</div>
    <div id="data_D">Data D</div>
    <div id="data_B">Data B</div>
    <div id="data_C">Data C</div>
    <div id="data_E">Data E</div>
    <div id="data_F">Data F</div>
</div>

[0] = A
[1] = D
[2] = B
[3] = C
[4] = E
[5] = F

Only indexes 1 (new position) through 3 (previous position) are effected and require database updates to their weights.

My question is, how would I only serialize this particular dataset each time on an update?

Here is where I am at currently with my code:

$("#sortable").sortable({
    placeholder: "sortable-placeholder",
    start: function (event, ui) {
        $(this).attr('data-previndex', ui.item.index());
    },
    update: function (event, ui) {
        var newPosition = ui.item.index();
        var prevPosition = $(this).attr('data-previndex');

        $.ajax({
            type: "POST",
            url: "/topics/updateorder",
            // sends all data ** TODO: WE ONLY WANT TO PASS SERIALIZED DATA FOR INDEXES newPosition - prevPosition (or visa-versa) **
            data: $(this).sortable("serialize") // currently sends data[]=A&data[]=D&data[]=B&data[]=C&data[]=E&data[]=F, we want data[]=D&data[]=B&data[]=C
        });
    }
});

Obviously I need a custom serializer or some sort (I think?), just not sure how. One issue with only passing the changed data, however, is that I can no longer update weight’s based off of the indexes of the posted form data (since all of it is no longer passed). I will have to pass their index values relative to all the other data along with it somehow as well.

Thanks.

  • 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-30T19:33:48+00:00Added an answer on May 30, 2026 at 7:33 pm

    I would think an easier way of doing this would be to simply pass the new position of the element to the server. That way you’re not sending data for all the elements (which sounds like what you’re looking to avoid).

    Take a peek at the events for the sortable widget: http://jqueryui.com/demos/sortable/#events

    You could bind a function to update which could be used to get the new position of the element and send it to the server via ajax.

    Since the server knows the element and the old position of it, the server can handle the calculations needed to “push” all the remaining elements down one position, and you’re only sending a string and integer to the server in your request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've appended a sortable jQuery plugin to my list of divs using 1.4.1 jQuery.
I have a table that I've made sortable using the jQuery plugin Tablesorter 2.0
I'm currently using the jQuery sortable plugin and one of the things I can
I'm trying to create a sortable list using the Jquery sortable plugin. I want
I have the following ListView in which I am using the JQuery UI sortable
i am using this jquery to make a drag and drop sortable list. http://jqueryui.com/demos/sortable/
I'm using the sortable function in jquery to sequence a faq list. Needless to
I'm using the Sortable component of jQuery UI . The callbacks don't seem to
Using jQuery, is there a way to select all tag that reference a specific
I recently had a little problem using a jquery plugin with coffeescript (within the

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.