Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamically enable/disable jquery sortable item
    primarykey
    data
    text
    <p>I have table rows that are sortable depending on whether certain radio buttons are checked or not. The sortables are initialized on <code>document.ready</code> as follows:</p> <pre><code>$(document).ready(function() { // Return a helper with preserved width of cells // handy code I got from http://lanitdev.wordpress.com/2009/07/23/make-table-rows-sortable-using-jquery-ui-sortable/ var fixHelper = function(e, ui) { ui.children().each(function() { $(this).width($(this).width()); }); return ui; }; // #opts = table id; tr.ui-state-disabled class = rows not sortable $("#opts tbody").sortable({ items: 'tr:not(.ui-state-disabled)', cursor: 'crosshair', helper: fixHelper }).disableSelection(); }); </code></pre> <p>I have the following function attached to the radio buttons (ids prefixed "active_") <code>onchange</code> which either adds or removes the <code>ui-state-disabled</code> class attribute from table rows (dynamic ids prefixed "opt_"):</p> <pre><code> var toggleDrag = function(i){ if ($('#active_'+i+'-0').is(':checked')) { $('#opt_'+i).addClass('ui-state-disabled'); } if ($('#active_'+i+'-1').is(':checked')) { $('#opt_'+i).removeClass(); } $("#opts tbody").sortable("option", "items", "tr:not(.ui-state-disabled)"); //$("#opts tbody").sortable("refresh"); //alert($('#opt_'+i).attr('class')); - alert indicates that the class attribute is being changed //$("#opts tbody").sortable("option", "cursor", "auto"); - this works! } </code></pre> <p>If I select a radio button that should make a previously un-sortable row sortable, it works and I can drag and drop the row. The problem is if I select a radio button to make a row that previously was sortable, un-sortable, I can still drag and drop it. The setter <code>.sortable("option", "items", "tr:not..etc")</code> doesn't appear "un-register" a row if it was previously sortable. I also tried .sortable("refresh") with no luck. And I have checked to see if the class attribute is being changed with an alert and it is.</p> <p>Any help with this would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload