Hello,
I have implemented your drag n drop project located here and wrapped it around the RadzenGrid and tagged the columns with the dragable div.
It seems to work to a degree, but wondering if there is a better way to implement this?
In addition to your project project I added a class "Chart" in the Data folder.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace BlazorDragAndDrop.Data
{
public class Chart
{
public string LinkName { get; set; }
public string SourceNode { get; set; }
public string DestNode { get; set; }
public string ScriptID { get; set; }
public string Comments { get; set; }
public string ScriptDetails { get; set; }
}
}
And here is the new index.razor page code:
@page "/"
@using Radzen.Blazor;
@using BlazorDragAndDrop.Data
<Draggable Data="@ChartRow" Zone="Grid">
<RadzenGrid @ref="evGrid" AllowSorting="true" AllowPaging="true" PageSize="8" Data="@chartList" TItem="Chart" RowSelect="@RowSelect" SelectionMode="DataGridSelectionMode.Single">
<Columns>
<div class="draggable">
<RadzenGridColumn TItem="Chart" Property="LinkName" Title="Link Name" FormatString="{0:0.00000 THz}" Width="105px" />
<RadzenGridColumn TItem="Chart" Property="SourceNode" Title="Source Node" Width="80px" />
<RadzenGridColumn TItem="Chart" Property="DestNode" Title="Dest Node" FormatString="{0:0 G}" Width="60px" />
<RadzenGridColumn TItem="Chart" Property="Comments" Title="Comments" FormatString="{0:0 GHz}" Width="70px" />
<RadzenGridColumn TItem="Chart" Property="Engineer" Title="Engineer" Width="90px" />
</div>
</Columns>
</RadzenGrid>
</Draggable>
<br />
<br />
<DropTarget T="Chart" Drop="@OnDrop" Zone="Grid">
<div class="drop-target">
Drop here to send to DataBase
</div>
</DropTarget>
<br />
<br />
@if (dropMessage != null)
{
@dropMessage
}
@code {
string dropMessage = null;
Chart ChartRow;
List<Chart> chartList = new List<Chart>();
RadzenGrid<Chart> evGrid;
protected override void OnInitialized()
{
base.OnInitialized();
CreateChart();
}
private void RowSelect(Chart e)
{
ChartRow = e;
}
private void OnDrop(Chart data)
{
if (data != null)
{
string cData = data.SourceNode + " " + data.DestNode + " " + data.ScriptDetails;
dropMessage = $"Sent to DataBase: {cData}";
StateHasChanged();
}
}
private void CreateChart()
{
Chart chart = new Chart()
{
Comments = "Comments",
DestNode = "4321",
LinkName = "LinkName",
ScriptDetails = "ScriptDetails",
ScriptID = "666",
SourceNode = "1234"
};
chartList.Add(chart);
Chart chart2 = new Chart()
{
Comments = "Comments",
DestNode = "9876",
LinkName = "LinkName",
ScriptDetails = "ScriptDetails",
ScriptID = "999",
SourceNode = "12345"
};
chartList.Add(chart2);
Chart chart3 = new Chart()
{
Comments = "Comments",
DestNode = "142536",
LinkName = "LinkName",
ScriptDetails = "ScriptDetails",
ScriptID = "888",
SourceNode = "980756"
};
chartList.Add(chart3);
}
}
The drag image is the entire grid. I understand why it is, because I wrapped the whole grid as Draggable, that was the only place it would work.
Hoping you guys can do this a little better. I do have a contract, so if you need to email please do. Thanks for taking the time to look at this.
Kind regards,
Orlando