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

Drag and Drop not hitting update action

6 Answers 45 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Mathieu
Top achievements
Rank 1
Mathieu asked on 02 Jan 2019, 03:40 PM

Hi,

 

I have this config below for a treelist. You can see that I have enabled drag and drop by setting move to true.

I would expect, when I drag and drop an item from one parent to another, that the "update" action defined in my controller is hit with the model containing the parentId of the new parent, but the "update" action on the controller is not being hit !

What am I missing ?

@(Html.Kendo().TreeList<AccountGroupModel>()
              .Name("tlAccountGroup")
              .Toolbar(toolbar =>
              {
                  toolbar.Create();
              })
              .Columns(columns =>
              {
                  columns.Add().Field(f => f.Name);
                  columns.Add().Command(c =>
                  {
                      c.Edit();
                  });
              })
              .Editable(editable => editable.Move(true))
              .DataSource(datasource =>
                  datasource
                      .Model(model =>
                      {
                          model.Id(m => m.Id);
                          model.ParentId(m => m.ParentId);
                          model.Field(m => m.Name);
                      })
                      .Read(read => read.Action("AccountGroups_Read", "AccountGrouping"))
                      .Create(create => create.Action("AccountGroups_Create", "AccountGrouping"))
                      .Update(update => update.Action("AccountGroups_Update", "AccountGrouping"))
              ))

 

My controller actions look like this:

public async Task<JsonResult> AccountGroups_Read([DataSourceRequest] DataSourceRequest request)
        {
            var models = await accountGroupingService.GetAccountGroupsAsync();
            return Json(models.ToTreeDataSourceResult(request, e => e.Id, e => e.ParentId, e => e));
        }
 
        public async Task<JsonResult> AccountGroups_Create([DataSourceRequest] DataSourceRequest request, AccountGroupModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                model = await accountGroupingService.SaveAccountGroupAsync(model);
            }
 
            return Json(new[] {model}.ToTreeDataSourceResult(request, ModelState));
        }
 
        public async Task<JsonResult> AccountGroups_Update([DataSourceRequest] DataSourceRequest request, AccountGroupModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                model = await accountGroupingService.SaveAccountGroupAsync(model);
            }
 
            return Json(new[] { model }.ToTreeDataSourceResult(request, ModelState));
        }

6 Answers, 1 is accepted

Sort by
0
Mathieu
Top achievements
Rank 1
answered on 03 Jan 2019, 02:15 PM

Figured it out.

I subscribed to the "DragEnd" event and called .sync() on the datasource of the treelist.

Please correct me if that's not the way to go...

0
Konstantin Dikov
Telerik team
answered on 04 Jan 2019, 07:19 AM
Hi Mathieu,

You could also set the "AutoSync" property of the DataSource to "true", which will call the "sync" method on each change:
.DataSource(dataSource => dataSource
    .AutoSync(true)

Hope this helps.


Regards,
Konstantin Dikov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Dan
Top achievements
Rank 1
Iron
Veteran
answered on 08 Jul 2020, 09:02 AM

Hi Konstantin,

Unfortunatelly the setting of AutoSync has side effects like when you try to add a root it saves it automatically in the database without waiting for the user the enter values.

Is the "hack" that Mathieu suggested the only way for the drag and drop to function correctly?

0
Tsvetomir
Telerik team
answered on 13 Jul 2020, 07:36 AM

Hi Dan,

It is correct that the AutoSync option of the data source will perform a request every time there is a change in the data. For instance, after adding a row, or changing the values for any of the editors. 

The approach shared by Mathieu is a good option to go for. It simply saves the dirty items via the sync() method. The moved item is dirty due to the fact that its parentId field has changed.

 

Regards,
Tsvetomir
Progress Telerik

0
Dan
Top achievements
Rank 1
Iron
Veteran
answered on 13 Jul 2020, 07:47 AM

Hi Tsvetomir,

But still this is a "hack" and should not be necessary to be used especially when like me all the users expect that the drag & drop to save the dirty changes automatically at the end of the drag.

Could you tell me if there is a bug registered for this so I can vote and watch or can I add it.

0
Tsvetomir
Telerik team
answered on 15 Jul 2020, 02:13 PM

Hello, Dan,

The behavior that is observed should not be considered as a bug as the user should have the freedom to have the parentId automatically saved or not. If you would like to have a new property that should control the saving behavior, then, this item has to be considered as an enhancement to the existing functionality.

In cases that use the InCell edit mode with batch updates, the automatic updates will not be accepted as the developer would not want to send any additional requests. 

Nevertheless, feel free to share you thoughts and suggestions in our feedback portal. The items are reviewed by the dev team:

https://www.telerik.com/support/feedback

 

Regards,
Tsvetomir
Progress Telerik

Tags
TreeList
Asked by
Mathieu
Top achievements
Rank 1
Answers by
Mathieu
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Dan
Top achievements
Rank 1
Iron
Veteran
Tsvetomir
Telerik team
Share this question
or