I want to be able to drag items from Grid1 to Grid2 and then allow the user to sort the items of Grid2. Individually, the sortableRows option and gridDnd options work without issue. When both integrations are used together and the user sorts the rows within Grid2, the rows are duplicated as if they were dragged from Grid1.
Using jquery 1.4.4, jqueryui 1.8.10, jqGrid 4.2
Here is some sample code demonstrating the issue:
<script type="text/javascript">
$(document).ready(function () {
// Creating grid1
jQuery("#grid1").jqGrid({
datatype: "local",
height: 100,
colNames: ['Id1', 'Name1', 'Values1'],
colModel: [
{name: 'id1', index: 'id',width: 100},
{name: 'name1',index: 'name',width: 100},
{name: 'values1',index: 'values',width: 200}
],
caption: 'Grid 1',
pager: '#pgrid1'
});
// Creating grid2
jQuery("#grid2").jqGrid({
datatype: "local",
height: 'auto',
colNames: ['Id2', 'Name2', 'Values2'],
colModel: [
{name: 'id2',index: 'id',width: 100},
{name: 'name2',index: 'name', width: 100},
{name: 'values2',index: 'values',width: 200}],
caption: 'Grid 2',
pager: '#pgrid2'
});
// Data for grid1
var mydata1 = [
{id1:"1",name1:"test1",values1:'One'},
{id1:"2",name1:"test2",values1:'Two'},
{id1:"3",name1:"test3",values1:'Three'}
];
// Data for grid2
var mydata2 = [
{id2:"11",name2:"test11",values2:'One1'},
{id2:"21",name2:"test21",values2:'Two1'},
{id2:"31",name2:"test31",values2:'Three1'}
];
// Adding grid data
for (var i = 0; i <= mydata1.length; i++) {
jQuery("#grid1").jqGrid('addRowData',i + 1, mydata1[i]);
jQuery("#grid2").jqGrid('addRowData',i + 1, mydata2[i]);
}
// connect grid1 with grid2
jQuery("#grid1").jqGrid('gridDnD',{connectWith:'#grid2'});
// make grid2 sortable
jQuery("#grid2").jqGrid('sortableRows');
});
</script>
<table id="grid1">
<tr>
<td />
</tr>
</table>
<table id="grid2">
<tr>
<td />
</tr>
</table>
It seems a bug in the jqGrid code. I think that one should change the line 392 of the
grid.jqueryui.jsfromto
The corresponding line in the
jquery.jqGrid.src.jshas the number 11098. After the changes the original demo will be fixed to the following which seems work correct.UPDATED: I posted the bug report in the trirand forum where I described the problem and my suggestion to fix it. I hope that Tony will include the fix in the main code of jqGrid.
UPDATED 2: The bug is already fixed in the main code of jqGrid.