小编ann*_*tte的帖子

动态启用/禁用jquery可排序项

我有可以排序的表行,具体取决于是否检查了某些单选按钮.可排序的初始化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();
});
Run Code Online (Sandbox Code Playgroud)

我有以下功能附加到单选按钮(ID为"active_")onchange,它们ui-state-disabled从表行添加或删除类属性(动态ID前缀为"opt_"):

    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"); …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-ui jquery-ui-sortable

13
推荐指数
3
解决办法
2万
查看次数

标签 统计

jquery ×1

jquery-ui ×1

jquery-ui-sortable ×1