论坛首页 编程语言技术论坛

利用JQuery修改使表格具有可拖动功能

浏览 5457 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-06-20  

<%= javascript_include_tag "dragdrop/jquery-1.2.6.min.js", "dragdrop/jquery.tablednd.js" %>

<script type="text/javascript">
$(document).ready(function() {
$("#listProducts tr:even').addClass('alt')");
$("#listProducts").tableDnD({
onDragClass: "myDragClass",
onDrop: function(table, row) {
var rows = table.tBodies[0].rows;
var valueStr = "<input type='hidden' name='sortValue' value='";
for (var i=0; i<rows.length; i++) {
valueStr += rows[i].id+" ";
}
valueStr += "'/>";
$("#valueArea").html(valueStr);
}
});
});
</script>
<%= form_tag(:action => "sequenceModify") %>
<div id="valueArea"></div>
<% if @tag != nil %><input type="hidden" name="tag_id" value="<%= @tag.id %>"/>
<% end %>

<table class="list" cellpadding="0" cellspacing="0" id="listProducts">
<colgroup>
<col />
<col style="width:150px;" />
<col style="width:110px;" />
<col style="width:60px;" />
</colgroup>
<tr>
<th onclick="sortTable('listProducts', 1, 's')">Name</th>
<th onclick="sortTable('listProducts', 2, 's')">Code</th>
<th class="numeric" onclick="sortTable('listProducts', 3, 'n')">Price</th>
<th class="numeric" onclick="sortTable('listProducts', 4, 'n')">Quantity</th>
</tr>
<% if @products.length > 0 then %>
<% for product in @products %>
<tr class="<%= alternate %>" id="<%= product.id %>">
<td><%= link_to(h(product.name), :action => 'edit', :id => product) %></td>
<td><%= product.code %></td>
<td class="numeric"><%= number_to_currency(product.price) %></td>
<td class="numeric"><%= product.quantity %></td>
</tr>
<% end %>
<% else %>
<tr><td colspan="4">No products to show in this view.</td></tr>
<% end %>
</table>
<%if @tag != nil %>
<center><input type="submit" value=" Sequence Modify! "/></center>
<% end %>
<%= end_form_tag %>提交

 

 

 

controller:

 

def sequenceModify
    sortValue = params[:sortValue]
    sortValue = sortValue.split(" ");
    sortTemp = 1
    tag_id = params[:tag_id]
    sortValue.each{|product_id|
      if product_id != "" and product_id != nil
        ProductTag.update_all("sequence = #{sortTemp}", "tag_id = #{tag_id} and product_id =
#{product_id}")
        sortTemp += 1
      end
    }
    redirect_to :action => 'list_by_tags', :key => tag_id
 end

 

 

 

   发表时间:2008-06-20  
如果有演示页面,或者写点注释就更好了
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics