TreeList does not show just inserted row if custom template for edit is enabled

1 Answer 18 Views
TreeList
Oleg
Top achievements
Rank 1
Oleg asked on 18 Nov 2022, 09:23 PM

I am using TreeList to edit hierarchical data.  I have to use Custom Edit template to create/edit rows. But new row disappears after clicking on Update button in Popup window.  I have to refresh page to see new rows. What am I doing wrong? 

@(Html.Kendo().TreeList<Models.FlowItemModel>()
    .Name("treelist")
    .Toolbar(toolbar => toolbar.Create())
    .Columns(columns =>
    {
        columns.Add().Field(e => e.FieldType).Width(200).Title("Type");
        columns.Add().Field(e => e.FieldLabel);
        columns.Add().Field(f => f.LineNumber).Width(100).Title("#");
        columns.Add().Field(e => e.DropdownValues).Width(150).Title("DropDown");
        columns.Add().Width(350).Command(c =>
        {
            c.CreateChild().Text("Add child");
            c.Edit();
            c.Destroy();
        });
    })
    .Editable(editable => editable.Move(move => move.Reorderable(true)))
    .Editable(e => e.Mode("popup").TemplateName("CustomTreeListPopup"))
    .Filterable()
    .Sortable()
    .DataSource(dataSource => dataSource
        .Create(create => create.Action("CreateFlowItem", "Configurator").Data("getConfiguration"))
        .Read(read => read.Action("GetFlowItems", "Configurator").Data("getSelectedFlowItem"))
        .Update(update => update.Action("UpdateFlowItem", "Configurator").Data("getConfiguration"))
        .Destroy(delete => delete.Action("DeleteFlowItem", "Configurator"))
        .Model(m =>
        {
            m.Id(f => f.Id);
            m.ParentId(f => f.ParentId).Nullable(true);
            m.Field(f => f.LineNumber);
            m.Field(f => f.FieldLabel);
            m.Field(f => f.FieldType);
        })
    )
    .Events(events =>
     {
         events.DragEnd("onDragEnd");
     })
)

CustomTreeListPopup:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Kendo.Mvc
@using Kendo.Mvc.UI
@model Web.Models.FlowItemModel

<div class="k-edit-form-container">
    <h5>Flow Item</h5>
    <br />
    @Html.HiddenFor(model => model.Id, new { @id = "edit_Id", @Name = "edit_Id" })
    @Html.HiddenFor(model => model.ParentId, new { @id = "edit_ParentId", @Name = "edit_ParentId" })
    <div class="editor-label">
        @Html.LabelFor(model => model.FieldLabel)
    </div>
    <div class="k-edit-field">
        @Html.EditorFor(model => model.FieldLabel)
        @Html.ValidationMessageFor(model => model.FieldLabel)
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.FieldType)
    </div>
    <div class="k-edit-field">
        @(Html.Kendo().DropDownListFor(model => model.FieldType)
            .HtmlAttributes(new { style = "width:100%" })
            .AutoBind(false)
            .DataSource(source =>
            {
                source.Read(read =>
                {
                    read.Action("GetFieldTypes", "Configurator");
                });
            })
            )
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.DropdownValues)
    </div>
    <div class="k-edit-field">
        @Html.EditorFor(model => model.DropdownValues)
        @Html.ValidationMessageFor(model => model.DropdownValues)
    </div>
</div>

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 23 Nov 2022, 09:38 AM

Hi Oleg,

Looking at the configuration of the TreeList and the custom editor template I do not see anything that might be causing the reported behavior. Does the behavior occur when using the default popup edit template?

Also what is the configuration of the remote endpoint? Note the create action should return the newly created item, as demonstrated in the TreeList Popup Editing Demo:

        public JsonResult Create([DataSourceRequest] DataSourceRequest request, EmployeeDirectoryModel employee)
        {
            if (ModelState.IsValid)
            {
                employeeDirectory.Insert(employee, ModelState);
            }

            return Json(new[] { employee }.ToTreeDataSourceResult(request, ModelState));
        }

Also are there any errors logged on the DevTools console or exceptions thrown?

Regards,
Aleksandar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
TreeList
Asked by
Oleg
Top achievements
Rank 1
Answers by
Aleksandar
Telerik team
Share this question
or