简体   繁体   English

jQuery多个可排序表

[英]jQuery multiple sortable tables

This question is best read with the fiddle open ;). 提琴打开时最好阅读此问题;)。 I've got a tables inside a table. 我的桌子里面有桌子。 The inside grey tables need to be sorted in there own container. 内部灰色表需要在自己的容器中排序。 So the grey rows can only be moved in the grey table. 因此,灰色行只能在灰色表中移动。 But the white rows need to move there grey table with them. 但是白色的行需要与它们一起移动到灰色的表中。 So you cannot move a white row or a grey table on there own, they are connected. 因此,您不能自己移动白色行或灰色表,因为它们已连接。

Here is my fiddle for what I got right now: 这是我现在所得到的东西:

fiddle 小提琴

options = {
helper: (event, ui) -> 
    children = ui.children()
    view = ui.clone()

    view.children().each (index) ->           
        $(@).width(children.eq(index).width())
    return view
}


$('#ccc').find('tbody').sortable(options)

I've been cracking my head on this all day but I cannot figure out how to like a grey table to a white row. 我整天都在挣扎,但我不知道该如何将灰色桌子变成白色行。

With your current html structure this is quite difficult to achieve. 使用当前的html结构,这很难实现。

First of all you need two sortables (one to sort big chunks with white headers and second to sort inside grey tables). 首先,您需要两个sortables(一个用于对带有白色标题的大块进行排序,第二个用于对灰色表进行排序)。

You want to be able to move big tables with small ones inside but as these were all inside sibling elements ( tr ) it was not really possible (so I've added multiple <tbody> s in there). 您希望能够移动带有小表的大表,但是由于它们都在同级元素( tr )内,所以这实际上是不可能的(因此我在其中添加了多个<tbody> )。

Anyway here's the working fiddle: https://jsfiddle.net/9vmvjqm4/5/ 无论如何,这是工作中的小提琴: https : //jsfiddle.net/9vmvjqm4/5/

You still need to exclude thead from being sortable. 您仍然需要将thead排除在可排序范围之外。 I don't like CoffeeScript so I left that (add items : ':not(thead)' ) to options (or sth like that, there are topics how to do that on stackOverflow). 我不喜欢CoffeeScript,所以我把它(添加items : ':not(thead)' )添加到options (或类似的东西,有一些主题如何在stackOverflow上实现)。

Also, have a look at this: http://johnny.github.io/jquery-sortable/ 另外,看看这个: http : //johnny.github.io/jquery-sortable/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM