2011-10-17 47 views
1

我在jqGrid中使用tableToGrid方法創建兩個網格。現在我想讓這兩行之間的行可以拖放。在選項中簡單添加'gridDnD' : true不起作用。它是如何完成的?在jqGrid中組合tableToGrid和gridDnd

實施例:

<script type="text/javascript"> 
$(function() { 
tableToGrid("#table1", { gridDnD: {connectWith: "#table2" } }); 
tableToGrid("#table2", { gridDnD: {connectWith: "#table2" } }); 
} 
</script> 

<table id="table1"> 
<thead> 
<tr> 
<th>Col 1</th> 
<th>Col 2</th> 
</tr> 
</thead> 
<tbody> 
<tr> 
<td>Val 1</td> 
<td>Val 2</tr> 
</tr> 
</tbody> 
</table> 

<table id="table2"> 
<thead> 
<tr> 
<th>Col 1</th> 
<th>Col 2</th> 
</tr> 
</thead> 
</table> 
+0

已經在下面的答案:http://stackoverflow.com/questions/2819384/jqgrid-move-drag-rows –

回答

1

gridDnD是的jqGrid的方法,而不是它可以在tableToGrid直接使用的選項。所以,你必須將代碼改寫爲類似如下:

tableToGrid("#table1"); 
tableToGrid("#table2"); 
$("#table1").jqGrid('gridDnD', {connectWith: "#table2"}); 
$("#table2").jqGrid('gridDnD', {connectWith: "#table1"}); 

the demo

修訂:我分析了問題拖&下降期間應對行代替移動。這個問題似乎是jQueryGrid與版本1.8.13開始的jQuery UI的兼容性問題。如何在the demo上看到使用jQuery UI 1.8.12的代碼能否正常工作。

我發現的grid.jqueryui.js code的線(線jquery.jqGrid.src.js 11078-11079)

var ids = $(ui.helper).attr("id"); 
$($t).jqGrid('delRowData',ids); 

是問題的根源。 ui.helper[0]包含從jQuery UI 1.8.13開始的刪除行,其空ID爲

如果您想更改代碼以

var id = this.id; 
$($t).jqGrid('delRowData',id); 

代碼將在這兩個新的jQuery UI(與16年8月1日進行測試),並在舊的(1.8.12)工作。請參閱相應的演示here

我目前沒有時間更精確地分析jQuery UI 1.8.12和1.8.13之間的變化。可能是jQuery UI中存在一個錯誤。不過,我會發布我的建議作爲trirand forum中的錯誤修正。我認爲這將是很好的jqGrid代碼與jQuery UI的不同版本具有較少的兼容性問題。

+0

啊哈,謝謝。但是,有一些奇怪的行爲。在你的演示中,拖動一行拷貝它。這是爲什麼? – carlpett

+0

@carlpett:查看我的答案的更新部分。 – Oleg

+0

夢幻般的工作!如果只有我可以upvote不止一次... – carlpett