1

我有一个自动生成 X 个表的应用程序,并根据它们的值为它们分配随机 id。然后,我有一个充当数据池的主表,在将数据放入新表之前将其存储在其中。

最终,一旦将数据存储在它的新表中,它将是可排序的,因此我可以更改表的层次结构。此外,它应该能够从其表中移出并移入任何其他表。我计划使用一个小按钮/图像在每个表中上下移动数据,但是从一个表移动到另一个表应该能够在单击该行时起作用。

我在网上看到的所有教程和代码片段都显示了在表之间移动数据,但是在您的 jquery 脚本中,您必须手动分配所有表类和 id。我不能这样做,因为它们对于从初始 SQL 查询返回的内容是可变的。

我当前的 html 模板看起来像这样(我知道它不会工作,但可拖放和可拖放只是为了向您展示我希望它如何工作)。这甚至可以使用 jquery,还是我应该寻找另一条路线?

<script>
$(function() {
    $( ".draggable" ).draggable();
    $( ".droppable" ).droppable({
        drop: function( event, ui ) {
            $( this )
                .addClass( "ui-state-highlight" )
                .find( "p" )
                    .html( "Dropped!" );
        }
    });
});
</script>

{% for vehicle in vehicles %} <!-- List the vehicles available -->
<h1>{{ vehicle.reg }} </h1>
<table class="listing droppable" id="{{ vehicle.reg }}">
<tr>
<th>Account #</th>
<th>Customer</th>
<th>Order #</th>
<th>Order Weight</th>
</tr>
<!-- want items to be dropped as rows in here -->
</table>
<br /><br />
{% endfor %}

<br /><br />
<h1>Unassigned Orders</h1>
<table class="listing">
<tr>
<th>Account #</th>
<th>Customer</th>
<th>Order #</th>
<th>Order Weight</th>
</tr>
{% for order in orders %}
<tr class="draggable"> <!-- rows should be able to get dropped into any vehicle table -->
<td>{{ order.oh_custaccref }}</td> <!-- and then into any other table (if required) -->
<td>{{ order.name }}</td> 
<td>{{ order.oh_orderno }}</td>  
<td>{{ order.oh_orderwgt }}</td>  
</tr>

{% endfor %}
</table>
4

1 回答 1

1

我用http://www.redips.net/javascript/drag-and-drop-table-content/解决了这个问题

它是一个非常酷的扩展,可让您在表格内和表格之间移动单元格和整行。

我的 html 模板最终变成:

<div id="drag">
{% for vehicle in vehicles %} <!-- List the vehicles available -->
<table class="listing" id="{{ vehicle.reg }}">
<colgroup><col width="100"/><col width="120"/><col width="480"/><col width="100"/><col width="100"/></colgroup>
<tr>
<th class="mark">{{ vehicle.reg }}</th>
</tr>
<tr>
<th class="mark">  </th>    
<th class="mark">Account #</th>
<th class="mark">Customer</th>
<th class="mark">Order #</th>
<th class="mark">Order Weight</th>
</tr>
<tr> 
<td class="rowhandler"><div class="drag row"></div> </td> 
<td></td> 
<td></td> 
<td></td>  
<td></td>
</tr>
<!-- want items to be dropped as rows in here -->
</table>
{% endfor %}

<table class="listing">
<colgroup><col width="100"/><col width="120"/><col width="480"/><col width="100"/><col width="100"/></colgroup>
<tr>
<th class="mark">NO REG</th>
</tr>
<tr>
<th class="mark">  </th>    
<th class="mark">Account #</th>
<th class="mark">Customer</th>
<th class="mark">Order #</th>
<th class="mark">Order Weight</th>
</tr>   
{% for order in orders %}
<tr> 
<!-- rows should be able to get dropped into any vehicle table -->
<td class="rowhandler"><div class="drag row"></div> </td> 
<td>{{ order.oh_custaccref }}</td> <!-- and then into any other table (if required) -->
<td>{{ order.name }}</td> 
<td>{{ order.oh_orderno }}</td>  
<td>{{ order.oh_orderwgt }}</td>
</tr>

{% endfor %}    
</table>
</div> <!-- end drag -->
{% endblock %}
于 2012-07-31T15:01:04.323 回答