Prevent Drag Drop of certain nodes

2 posts, 0 answers
  1. Paul
    Paul avatar
    35 posts
    Member since:
    Jan 2014

    Posted 11 Oct 2015 Link to this post

    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

  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 13 Oct 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top