Hi all,
I am using a RadTreeList with drag and drop enabled. This works fine.
Now I want to prevent items at the highest level from being dropped on another item. These items cannot be the child of another item.
How can I accomplish this?
I think I can prevent the dropping of certain items in the itemDragging, but I don't know how to access the dragged_item here.
Then I can do something like:
if (level of the dragged item is zero) then args.set_canDrop(false);
Annet
I am using a RadTreeList with drag and drop enabled. This works fine.
Now I want to prevent items at the highest level from being dropped on another item. These items cannot be the child of another item.
How can I accomplish this?
I think I can prevent the dropping of certain items in the itemDragging, but I don't know how to access the dragged_item here.
Then I can do something like:
if (level of the dragged item is zero) then args.set_canDrop(false);
Annet
4 Answers, 1 is accepted
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 24 Sep 2011, 04:07 PM
What if you do it on the server side in OnItemDrop and just check if the item draggings parent is null...if it is just set cancelled to true?
http://www.telerik.com/help/aspnet-ajax/treelist-items-drag-drop.html
Steve
http://www.telerik.com/help/aspnet-ajax/treelist-items-drag-drop.html
Steve
0
annet
Top achievements
Rank 1
answered on 26 Sep 2011, 09:03 AM
Thank you Steve, this prevents the actual dropping of the item, which I also needed to do.
But during dragging, I would like to give the user a visible clue when an item can't be dropped.
I use the client-side itemDragging for that, like in the Telerik demo.
Can this be done?
Annet
But during dragging, I would like to give the user a visible clue when an item can't be dropped.
I use the client-side itemDragging for that, like in the Telerik demo.
Can this be done?
Annet
0
Accepted
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 26 Sep 2011, 03:26 PM
Well setting cancel prevents the item being dropped if the condition is met, setting it globally clearly isn't the way to go :)
So this is something I did recently
So this is the line that checks to see if it's being dragged into the header, and that's where you'd cancel with a message
NOW, clientside though it looks like it might be easy as well
Handle OnItemDropping
Now this is me just looking at the documentation and winging it, so I'm not entirely sure if that will work, but seems okay
So this is something I did recently
public
void
OnWorkflowList_ItemDrop(
object
sender, TreeListItemDragDropEventArgs e) {
var item = e.DraggedItems.First();
var dataItem = item.DataItem
as
Approval;
var approvalID = item.GetDataKeyValue(
"ApprovalID"
);
var parentApprovalID = item.GetDataKeyValue(
"ParentApprovalID"
);
Approval approval =
base
.RTOContext.Approvals.Get(
new
Guid(approvalID.ToString()));
Approval parentApproval =
null
;
if
(parentApprovalID !=
null
) {
parentApproval =
base
.RTOContext.Approvals.Get(
new
Guid(parentApprovalID.ToString()));
}
//We're dragging to the header
if
(e.DestinationDataItem ==
null
) {
if
((approval.PickTypeID != (
byte
)WorkflowItemsTypeEnum.Assigned || approval.PickTypeID != (
byte
)WorkflowItemsTypeEnum.Assigned) && approval.ApproverID ==
null
) {
//Not possible to drag an unknown approver item to the root with nobody to pick it
e.Canceled =
true
;
commandMessageLiteral.Text =
"Invalid Re-order, item has no defined approver, so nobody will be able to pick them (cats and dogs living together, mass hysteria)"
;
}
}
else
{
//Check to see if the item we're dropping it on is approved, and this person doesn't have an approver assigned
if
(approval.ApproverID ==
null
&& (parentApproval.StatusType != StatusType.Pending || parentApproval.StatusType != StatusType.NotRequired || parentApproval.StatusType != StatusType.Empty)) {
e.Canceled =
true
;
commandMessageLiteral.Text =
"Invalid Re-order, the item you're dropping it onto isn't pending, so nobody will be able to pick this person"
;
}
}
}
So this is the line that checks to see if it's being dragged into the header, and that's where you'd cancel with a message
//We're dragging to the header
if
(e.DestinationDataItem ==
null
) {
NOW, clientside though it looks like it might be easy as well
Handle OnItemDropping
function
onItemDropping(sender, args){
var
dataItem = args.get_targetDataItem();
if
(dataItem.get_isRoot()){
args.set_cancel(
true
);
//I believe this is how to cancel
}
}
0
annet
Top achievements
Rank 1
answered on 26 Sep 2011, 03:59 PM
Thanks for your input. I can't get it to work client-side, so I settled for the server-side solution.
Annet
Annet