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