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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:24:38+00:00 2026-05-27T15:24:38+00:00

I want a row in a jQuery UI Sortable to be sortable only if

  • 0

I want a row in a jQuery UI Sortable to be sortable only if it has a cansort class. I have it set to cancel: ':not(.cansort)' but it refuses to let me sort anything at all, including the rows that have the cansort class.

I know I can add a disabled class explicitly, but I use the cansort class for other purposes, so that means each time I made something sortable I would have to remove the disabled class and add the cansort class. I don’t want to have to add and remove a class each time I toggle something to be sortable.

I don’t want to restrict what’s sortable in the items property because every element can be sortable and I only dynamically toggle it on and off using the cansort class.

  • 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-27T15:24:39+00:00Added an answer on May 27, 2026 at 3:24 pm

    The reason for this is the way that the cancel option is processed by the ui.mouse widget (a widget used by several jQueryUI widgets to handle mouse events). Check out this line of code:

    elIsCancel = (typeof this.options.cancel == "string" 
        && event.target.nodeName ? 
            $(event.target).closest(this.options.cancel).length : false);
    

    What this means is that your selector gets run with the closest on the element that was mousedowned on. So lets take an li.cansort sortable item. That will generate a jQuery selector that looks something like this:

    $("li.cansort").closest(":not(.cansort)").length;
    

    This will always return a length of 1, because the parent ul for all the sortable lis does not have the .cansort class. This means with that kind of selector, the sorting will always be canceled.

    Luckily, this is easy to get around if you just include the tag name in your cancel selector:

    cancel: "li:not(.cansort)"
    

    Here’s an example: http://jsfiddle.net/7hSnc/ (try removing the li from the cancel selector)

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

Sidebar

Related Questions

I want to highlight a table row by changing its color, using jQuery. Have
So, let's say I have a large set of elements to which I want
I have multiple tables that are randomly generated. I only want the first row
I want to duplicate a row, not the keys of course, without explicity using
I want to delete a row in the grid, but the grid always post's
I want to have a button in each row to delete the corresponding row.
Using jQuery, how can I create a clone of a Row which has display:
I have an ASP.NET gridview I want to manipulate using JavaScript/JQuery. The problem I
Hi I am appending columns to a row though jquery. I have a row
I have a table row with 5 cells. I want to click an image

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.