This is a migrated thread and some comments may be shown as answers.

RadGrid Drag and Drop Functionality

1 Answer 157 Views
Interesting resources
This is a migrated thread and some comments may be shown as answers.
Monika
Top achievements
Rank 1
Monika asked on 09 Jun 2009, 06:30 AM
Hello Telerik

I have implement Drag and drop functionality in my page usign RadGrid. But I am not able to achieve this functionality.
I have taken reference of telerik Demo application 
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/draganddrop/defaultcs.aspx

But in this demo also reordring of grid rows is not working. Only movement of rows between within two grid is working 

   .aspx page code

<

 

radControls:RadScriptBlock runat="server" ID="scriptBlock">

 

 

<script type="text/javascript">

 

 

function onRowDropping(sender, args)

 

{

 

if (sender.get_id() == "<%=grdFieldValueList.ClientID %>")

 

{

 

var node = args.get_destinationHtmlElement();

 

 

if(!isChildOf('<%=grdFieldValueList.ClientID %>', node) )

 

{

args.set_cancel(

true);

 

}

}

}

 

 

function isChildOf(parentId, element)

 

{

 

while(element)

 

{

 

if (element.id && element.id.indexOf(parentId) > -1)

 

{

 

return true;

 

}

element = element.parentNode;

}

 

return false;

 

}

 

 

</script>

 


<radControls:RadGrid ID="grdFieldValueList" runat=server AutoGenerateColumns=false OnRowDrop="grdFieldValueList_RowDrop">

 

<ClientSettings AllowRowsDragDrop=true >

 

 

<Selecting AllowRowSelect="True" EnableDragToSelectRows="true"/>

 

 

<ClientEvents OnRowDropping="onRowDropping" />

 

 

<Scrolling AllowScroll="true" UseStaticHeaders="true" />

 

 

</ClientSettings>

 

 

<MasterTableView DataKeyNames="FieldCode" GridLines="Both" BackColor="White">

 

 

<Columns>

 

 

 

<radControls:GridBoundColumn DataField="FieldCode"></radControls:GridBoundColumn>

 

 

<radControls:GridBoundColumn DataField="DisplayName"></radControls:GridBoundColumn>

 

 

 

</Columns>

 

 

</MasterTableView >

 

 

 

</radControls:RadGrid>

 


aspx.cs page code

 

private static DWField GetFieldValue(IList<DWField> valuesToSearchIn, int FieldCode)

 

{

 

foreach (DWField fieldValue in valuesToSearchIn)

 

{

 

if (fieldValue.FieldCode == FieldCode)

 

{

 

return fieldValue;

 

}

}

 

return null;

 

}

 

 

protected void grdFieldValueList_RowDrop(object sender, GridDragDropEventArgs e)

 

{

 

if (e.DestDataItem != null && e.DestDataItem.OwnerGridID == grdFieldValueList.ClientID)

 

{

 

//reorder items in grid

 

 

IList<DWField> fieldValueList = (IList<DWField>)Session["FieldList"];

 

 

DWField tmpFieldValue = GetFieldValue(fieldValueList, (int)e.DestDataItem.GetDataKeyValue("FieldCode"));

 

 

int destinationIndex = fieldValueList.IndexOf(tmpFieldValue);

 

 

if (e.DropPosition == GridItemDropPosition.Above && e.DestDataItem.ItemIndex > e.DraggedItems[0].ItemIndex)

 

{

destinationIndex -= 1;

}

 

if (e.DropPosition == GridItemDropPosition.Below && e.DestDataItem.ItemIndex < e.DraggedItems[0].ItemIndex)

 

{

destinationIndex += 1;

}

 

List<DWField> ValuesToMove = new List<DWField>();

 

 

foreach (GridDataItem draggedItem in e.DraggedItems)

 

{

 

DWField tmpOrder = GetFieldValue(fieldValueList, (int)draggedItem.GetDataKeyValue("FieldCode"));

 

 

if (tmpOrder != null)

 

ValuesToMove.Add(tmpOrder);

}

 

foreach (DWField dwField in ValuesToMove)

 

{

fieldValueList.Remove(dwField);

fieldValueList.Insert(destinationIndex, dwField);

}

 

Session[

"FieldValueList"] = fieldValueList;

 

grdFieldValueList.DataSource = fieldValueList;

grdFieldValueList.DataBind();

 

//grdFieldValues.Rebind();

 

e.DestDataItem.Selected =

true;

 

}

}


The problem is that RowDrop(Serevr side event is getting not fired  every time. It is getting fired sometimes and I am not able to find in which scenario it is getting fired .

Kindly provide me the resolution of this problem

Thanks
 Monika Sharma

1 Answer, 1 is accepted

Sort by
0
Bruno
Top achievements
Rank 2
answered on 12 Jun 2009, 06:09 AM
Strange but for me the example is running as expected. In the left grid you can reorder items and drag it to right grid. From the right grid you can drag items to the trash can.

--Bruno
Tags
Interesting resources
Asked by
Monika
Top achievements
Rank 1
Answers by
Bruno
Top achievements
Rank 2
Share this question
or