jquery UI Sortable with table and tr width

前端 未结 12 740
不知归路
不知归路 2020-11-28 18:02

I am using jQuery UI sortable to make my table grid sortable. The code seems to work fine but because I am not adding width to tds, when I drag the tr

相关标签:
12条回答
  • 2020-11-28 18:55

    Apply the sortable to the table's tbody element and just set the helper to 'clone', as described in jquery-ui's API

    $("$my-table-tbody").sortable({
        helper: "clone"
    });
    
    0 讨论(0)
  • 2020-11-28 18:56

    Call this following code when your table is ready to be sorted, this will make sure your td elements has a fixed with without breaking table structure.

     $(".tableToSort td").each(function () {
                $(this).css("width", $(this).width());
            });  
    
    0 讨论(0)
  • 2020-11-28 18:57

    I think it can help:

    .ui-sortable-helper {
        display: table;
    }
    
    0 讨论(0)
  • 2020-11-28 18:57

    It seems like disableSelection() - method is bad and deprecated nowadays. I can't use text inputs inside sort-able row anymore in Mozilla Firefox 35.0. It just isn't focusable anymore.

    0 讨论(0)
  • 2020-11-28 18:58
    .sortable({
        helper: function (e, ui) {
            ui.children().each(function () {
                $(this).width($(this).width());
            });
            return ui;
        }
    });
    
    0 讨论(0)
  • 2020-11-28 19:03
    $(function() {
        $( "#sort tbody" ).sortable({
            update: function () {
                                    var order = $(this).sortable("toArray").join();
                                    $.cookie("sortableOrder", order);
                            }
        });
        if($.cookie("sortableOrder")){
            var order = $.cookie("sortableOrder").split(",");
            reorder(order, $("#sort tbody"));
        }
        function reorder(aryOrder, element){
          $.each(aryOrder, function(key, val){
                  element.append($("#"+val));
          });
        }
      });
    
    0 讨论(0)
提交回复
热议问题