I am not able to drag and drop between grids when one of the grids starts out with an empty list of data. I have used your code from the example and altered it to make one grid empty to start out with. When I try to drag a new item into that grid I just get the "not allowed" tooltip and nothing will drop.
@page "/DragDropTest"
@layout AuthorizedMainLayout
@* Drag a row from one Grid and Drop it in the other *@
<TelerikGrid Data="@MyData" Height="400px"
Pageable="true" Sortable="true"
FilterMode="Telerik.Blazor.GridFilterMode.FilterRow"
Resizable="true" Reorderable="true"
@ref="@FirstGrid"
RowDraggable="true"
OnRowDrop="@((GridRowDropEventArgs<SampleData> args) => OnRowDropHandler(args))">
<GridSettings>
<GridRowDraggableSettings DragClueField="@nameof(SampleData.Name)"></GridRowDraggableSettings>
</GridSettings>
<GridColumns>
<GridColumn Field="@(nameof(SampleData.Id))" Width="120px" />
<GridColumn Field="@(nameof(SampleData.Name))" Title="Employee Name" Groupable="false" />
<GridColumn Field="@(nameof(SampleData.Team))" Title="Team" />
<GridColumn Field="@(nameof(SampleData.HireDate))" Title="Hire Date" />
</GridColumns>
</TelerikGrid>
<TelerikGrid Data="@MySecondGridData" Height="400px"
Pageable="true"
Resizable="true"
Reorderable="true"
RowDraggable="true"
OnRowDrop="@((GridRowDropEventArgs<SampleData> args) => OnSecondGridRowDropHandler(args))">
<GridSettings>
<GridRowDraggableSettings DragClueField="@nameof(SampleData.Name)"></GridRowDraggableSettings>
</GridSettings>
<GridColumns>
<GridColumn Field="@(nameof(SampleData.Id))" Width="120px" />
<GridColumn Field="@(nameof(SampleData.Name))" Title="Employee Name" Groupable="false" />
<GridColumn Field="@(nameof(SampleData.Team))" Title="Team" />
<GridColumn Field="@(nameof(SampleData.HireDate))" Title="Hire Date" />
</GridColumns>
</TelerikGrid>
@code {
TelerikGrid<SampleData> FirstGrid { get; set; }
private void OnRowDropHandler(GridRowDropEventArgs<SampleData> args)
{
//The data manipulations in this example are to showcase a basic scenario.
//In your application you should implement them as per the needs of the project.
MyData.Remove(args.Item);
InsertItem(args);
}
private void OnSecondGridRowDropHandler(GridRowDropEventArgs<SampleData> args)
{
//The data manipulations in this example are to showcase a basic scenario.
//In your application you should implement them as per the needs of the project.
MySecondGridData.Remove(args.Item);
InsertItem(args);
}
private void InsertItem(GridRowDropEventArgs<SampleData> args)
{
var destinationData = args.DestinationGrid == FirstGrid ? MyData : MySecondGridData;
var destinationIndex = 0;
if (args.DestinationItem != null)
{
destinationIndex = destinationData.IndexOf(args.DestinationItem);
if (args.DropPosition == GridRowDropPosition.After)
{
destinationIndex += 1;
}
}
destinationData.InsertRange(destinationIndex, args.Items);
}
public List<SampleData> MySecondGridData = Enumerable.Range(1, 30).Select(x => new SampleData
{
Id = x + 2,
Name = "name " + x + 2,
Team = "team " + x % 3,
HireDate = DateTime.Now.AddDays(-x * 2).Date
}).ToList();
public List<SampleData> MyData = new(); // Enumerable.Range(1, 30).Select(x => new SampleData
//{
// Id = x,
// Name = "name " + x,
// Team = "team " + x % 5,
// HireDate = DateTime.Now.AddDays(-x).Date
//}).ToList();
public class SampleData
{
public int Id { get; set; }
public string Name { get; set; }
public string Team { get; set; }
public DateTime HireDate { get; set; }
}
}
Have you already found a solution?
I needed this in my application as well. But had no problems with it. Try to place the element at the top.
(If not, I'll check tomorrow!)
Regards Matthias
I am not sure what you mean by "Try to place the element at the top"
When I drag the element to the empty grid no matter where I try to place it is get the circle with the line through it and I can not drop it.