我有一些表格行,取决于某些单选按钮是否被选中而可排序。这些可排序项将在document.ready
初始化,如下所示:
$(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();
});
我有一个函数附加在单选按钮(id以"active_"为前缀)的onchange
事件上,它会从表格行(动态id以"opt_"为前缀)中添加或删除ui-state-disabled
类属性:
我有一个与单选按钮相关联的函数(ids前缀为“active_”),该函数将添加或删除表格行(动态ids前缀为“opt_”)的ui-state-disabled
类属性:
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!
}
如果我选中一个单选按钮,应该会使以前无法排序的行变得可排序,这样它就可以被拖放了。问题在于,如果我选择一个单选按钮使一行先前变成不可排序,我仍然可以拖放它。使用setter .sortable("option", "items", "tr:not..etc")
似乎不能“注销”已经被排序的行。我也尝试过用 .sortable("refresh"),但没有成功。我已经检查过类属性是否被更改,弹出了一个警报。
非常感谢任何帮助。
cancel
对我很有效,即使没有像您提到的那样在拖动时腾出空间 - 可能由于您的答案已经修复了。 - Ronny