|
<SfTreeGrid @ref="treeGrid" DataSource="@TreeData" IdMapping="TaskID"
ParentIdMapping="ParentID" TreeColumnIndex="1" AllowPaging="false"
AllowRowDragAndDrop="true" EnableCollapseAll="true">
<TreeGridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple">
</TreeGridSelectionSettings>
<TreeGridEditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true"
NewRowPosition="RowPosition.Below"
Mode="Syncfusion.Blazor.TreeGrid.EditMode.Row"
ShowConfirmDialog="true"></TreeGridEditSettings>
<TreeGridEvents OnActionComplete="ActionCompleteHandler"
TValue="SelfReferenceData"></TreeGridEvents>
</SfTreeGrid>
public static SfTreeGrid<SelfReferenceData> treeGrid { get; set; }
public static int ID { get; set; }
public static int? PID { get; set; }
public void ActionCompleteHandler(ActionEventArgs<SelfReferenceData> args)
{
if (args.RequestType == Syncfusion.Blazor.Grids.Action.RowDragAndDrop)
{
var data = treeGrid.GetCurrentViewRecords();
var droppedData = data.Where(p => p.TaskID == ID).FirstOrDefault();
var droppedIndex = data.FindIndex(d => d.TaskID == ID); // index of dropped data
PID = droppedData.ParentID; // parent id of dropped data
if (PID != null)
{
var parent = data.Where(p => p.TaskID == PID).FirstOrDefault();
droppedData.ItemLevel = parent.ItemLevel + 1; // setting new level value
}
else
{
droppedData.ItemLevel = 1;
}
treeGrid.UpdateRow(droppedIndex, droppedData);
//updating level using UpdateRow method
if (droppedData.isParent == true) // if dropped record has child,
we need to update level of those child also
{
updateLevel(droppedData); //passing dropped record to updateLevel method
for updating child record levels
}
}
}
// method for updating level of child records of dropped record
public void updateLevel(SelfReferenceData droppedData)
{
var currentViewDatas = treeGrid.GetCurrentViewRecords();
for (var i = 0; i < currentViewDatas.Count; i++)
{
if (currentViewDatas[i].ParentID == droppedData.TaskID)
{
currentViewDatas[i].ItemLevel = droppedData.ItemLevel + 1;
treeGrid.UpdateRow(i, currentViewDatas[i]);
if (currentViewDatas[i].isParent == true)
{
updateLevel(currentViewDatas[i]);
}
}
}
} |