Fix reorder in ListView with groups not handled correctly in all cases (#348)

Fix reorder in ListView with groups not handled correctly in all cases

- Fixes reordering of an item when there are collapsed groups
- Fixes reordering of an item to the first position of a group
- Fixes reordering of an item to the last position of a group
This commit is contained in:
Ivan Todorov 2018-11-28 13:31:40 +02:00 коммит произвёл GitHub
Родитель d91f645671
Коммит 17de78d78d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 27 добавлений и 32 удалений

Просмотреть файл

@ -267,11 +267,36 @@ namespace Telerik.UI.Xaml.Controls.Data.ListView
this.FinalizeReorder(context);
var isExecuted = false;
RadListViewItem destinationItem = null;
ItemReorderPlacement placement = 0;
if (data.InitialSourceIndex != data.CurrentSourceReorderIndex)
if (data.InitialSourceIndex < data.CurrentSourceReorderIndex)
{
destinationItem = this.reorderCoordinator.Host.ElementAt(data.CurrentSourceReorderIndex - 1) as RadListViewItem;
placement = ItemReorderPlacement.After;
if (destinationItem == null)
{
destinationItem = this.reorderCoordinator.Host.ElementAt(data.CurrentSourceReorderIndex + 1) as RadListViewItem;
placement = ItemReorderPlacement.Before;
}
}
else if (data.InitialSourceIndex > data.CurrentSourceReorderIndex)
{
destinationItem = this.reorderCoordinator.Host.ElementAt(data.CurrentSourceReorderIndex + 1) as RadListViewItem;
placement = ItemReorderPlacement.Before;
if (destinationItem == null)
{
destinationItem = this.reorderCoordinator.Host.ElementAt(data.CurrentSourceReorderIndex - 1) as RadListViewItem;
placement = ItemReorderPlacement.After;
}
}
if (destinationItem != null)
{
var dataItem = data.Data;
var destinationDataItem = this.GetDestinationDataItem(data.CurrentSourceReorderIndex);
var destinationDataItem = destinationItem.DataContext;
IDataGroup dataGroup = null;
IDataGroup destinationDataGroup = null;
@ -282,17 +307,6 @@ namespace Telerik.UI.Xaml.Controls.Data.ListView
destinationDataGroup = this.listView.Model.FindItemParentGroup(destinationDataItem);
}
ItemReorderPlacement placement;
if (data.InitialSourceIndex < data.CurrentSourceReorderIndex)
{
placement = ItemReorderPlacement.After;
}
else
{
placement = ItemReorderPlacement.Before;
}
var commandContext = new ItemReorderCompleteContext(dataItem, dataGroup, destinationDataItem, destinationDataGroup, placement);
isExecuted = this.ListView.commandService.ExecuteCommand(CommandId.ItemReorderComplete, commandContext);

Просмотреть файл

@ -831,24 +831,5 @@ namespace Telerik.UI.Xaml.Controls.Data.ListView
return canReorderColumn && (draggingFromStart || draggingFromEnd);
}
private object GetDestinationDataItem(int index)
{
int actualIndex = index;
if (this.listView.GroupDescriptors.Count == 0)
{
actualIndex = this.listView.Model.layoutController.strategy.GetElementFlatIndex(actualIndex);
}
var info = this.listView.Model.FindDataItemFromIndex(actualIndex);
object item = null;
if (info.HasValue)
{
item = info.Value.Item;
}
return item;
}
}
}