[英]Drag and Drop table columns using jquery Plugin
我有一個表,表頭固定,前3列固定。
http://jsfiddle.net/ncUdA/embedded/result/
我想拖放列(即A,B,C,D,E,F是應啟用移位(拖放)的列。它下面的所有元素也應移至新位置。
我發現了一個插件可以滿足我的要求,但是卻無法實現,因為我的代碼中使用了多個表來固定標題和固定3列。
http://johnny.github.com/jquery-sortable/#table
下面的代碼是有關如何執行此操作的插件代碼。
我正在使用把手進行模板制作。
var oldIndex
$('.sorted_head tr').sortable({
containerSelector: 'tr',
itemSelector: 'th',
placeholder: '<th class="placeholder"/>',
vertical: false,
onDragStart: function (item, group, _super) {
oldIndex = item.index()
item.appendTo(item.parent())
_super(item)
},
onDrop: function (item, container, _super) {
var field,
newIndex = item.index()
if(newIndex != oldIndex)
item.closest('table').find('tbody tr').each(function (i, row) {
row = $(row)
field = row.children().eq(oldIndex)
if(newIndex)
field.before(row.children()[newIndex])
else
row.prepend(field)
})
_super(item)
}
})
谷歌搜索后,找到解決方案以通過使用拖放來重新排序表列。 我發現'akottr'寫了一個很棒的jquery插件。 這里
它是與庫無關的js函數,使您能夠通過使用拖放操作來對表列進行重新排序。 它很容易使用。
$('#defaultTable').dragtable();
因此,我希望您可以根據需要獲得重新排序表。 查看更多示例: http : //akottr.github.io/dragtable/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.