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

Prevent Drag Drop of certain nodes

1 Answer 90 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 11 Oct 2015, 12:50 PM

I have the following model that I populate in the backend (controller):

public sealed class ItemGroupFlatModel
{
    public ItemGroupFlatModel()
    {
    }
 
    public int Id { get; set; }
 
    public string Name { get; set; }
 
    public string Description { get; set; }
 
    public int? ParentId { get; set; }
 
    public bool CanDelete { get; set; }
 
    public bool CanMove { get; set; }
 
    public bool AllowAdd { get; set; }
 
    public bool AllowEdit { get; set; }
}
 

and then pass to the front end using:

 

public JsonResult All([DataSourceRequest] DataSourceRequest request, int parentId)
{
    ItemGroupFlatViewModel model = _finderService.LoadFlatTreeModel(parentId);
 
    // null all parents that do not exist in tree
    List<int> ids = model.Children.Select(c => c.Id).ToList();
    model.Children.Where(c => c.ParentId.HasValue && !ids.Contains(c.ParentId.Value))
        .ToList().ForEach(c => c.ParentId = null);
 
    TreeDataSourceResult result = model.Children.ToTreeDataSourceResult(request,
        e => e.Id,
        e => e.ParentId,
        e => e
    );
 
    return Json(result, JsonRequestBehavior.AllowGet);
}

My Razor View is defined as:

<div class="demo-section k-header">
    @(Html.Kendo().TreeList<ItemGroupFlatModel>()
        .Name("itemgroup-treelist")
        .Columns(columns =>
        {
            columns.Add().Field(e => e.Name).Width(200); //.TemplateId("photo-template");
            columns.Add().Field(e => e.Description).Width(300);
            columns.Add().Width(200).Command(c =>
            {
                c.Edit();
                c.Destroy();
            });
        })
        .Editable(editable =>
        {
            editable.Move(true);
            editable.Mode("inline");
        })
        .Scrollable(true)
        .Selectable(true)
        .DataSource(dataSource => dataSource
            .Read(read => read.Action("All", "ItemGroup", new { parentId = Model.ParentId }))
            .ServerOperation(false)
            .Model(m =>
            {
                m.Id(f => f.Id);
                m.ParentId(f => f.ParentId);
                m.Expanded(true);
                m.Field(f => f.Name);
                m.Field(f => f.ParentId);
                m.Field(f => f.Id);
            })
        )
        .Height(540)
    )
</div>

I want to be able to control what can get dragged if  CanMove = true and prevent it if CanMove = false.  I want to prevent moving to a specific node if CanAdd = false and allow if CanMove = true.

Additionally, I want to prevent Delete if CanDelete = false.

Can this be done?

Cheers,

Andez

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 13 Oct 2015, 07:45 AM

Hello Paul,

This behavior is now possible by preventing the dragStart event. The event will be part of the next internal build, which should be available by the end of this week.

Regards,
Alex Gyoshev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TreeList
Asked by
Paul
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or