|
<SfTreeGrid DataSource="@TreeGridData" @ref="TreeGrid" IdMapping="TaskId" ParentIdMapping="ParentId" TreeColumnIndex="1" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<TreeGridEvents RowSelecting="RowSelectingHandler" Expanding="ExpandingHandler"
Collapsing="CollapsingHandler" TValue="TreeData.BusinessObject"></TreeGridEvents>
. . .
</SfTreeGrid>
@code{
public List<TreeData.BusinessObject> TreeGridData { get; set; }
SfTreeGrid<TreeData.BusinessObject> TreeGrid { get; set; }
public Boolean ExpandCollapseRow = false;
protected override void OnInitialized()
{
this.TreeGridData = TreeData.GetSelfDataSource().ToList();
}
public void RowSelectingHandler(RowSelectingEventArgs<TreeData.BusinessObject> args)
{
// preventing Row Selection
if (!this.ExpandCollapseRow)
{
this.TreeGrid.ExpandRow(args.Data); // expanding row on row click by calling ExpandRow method
}
this.ExpandCollapseRow = false;
}
public void ExpandingHandler(RowExpandingEventArgs<TreeData.BusinessObject> args)
{
// setting flag
this.ExpandCollapseRow = true;
}
public void CollapsingHandler(RowCollapsingEventArgs<TreeData.BusinessObject> args)
{
// setting flag
this.ExpandCollapseRow = true;
}
. .
} |
Thanks for quick response, It works fine but RowSelectingHandler and other handlers are also triggered when we click on Action Buttons on second or third grid column. Can we make it only specific for GridColumn containing Parent Child Data.
one more thing that most of the times Expand /Collapse icon changes state instantly but child data contained by the selected row takes too much time to load or show in the grid
|
<SfTreeGrid DataSource="@TreeGridData" @ref="TreeGrid" IdMapping="TaskId" ParentIdMapping="ParentId" TreeColumnIndex="1" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<TreeGridEvents RowSelecting="RowSelectingHandler" Expanding="ExpandingHandler"
Collapsing="CollapsingHandler" TValue="TreeData.BusinessObject"></TreeGridEvents>
<TreeGridColumns>
<TreeGridColumn Field="TaskId" HeaderText="Task ID" IsPrimaryKey="true" Width="80" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></TreeGridColumn>
. . .
</TreeGridColumns>
</SfTreeGrid>
@code{
public List<TreeData.BusinessObject> TreeGridData { get; set; }
SfTreeGrid<TreeData.BusinessObject> TreeGrid { get; set; }
public Boolean ExpandCollapseRow = false;
protected override void OnInitialized()
{
this.TreeGridData = TreeData.GetSelfDataSource().ToList();
}
public void RowSelectingHandler(RowSelectingEventArgs<TreeData.BusinessObject> args)
{
var rowTaskId = args.Data.TaskId;
var Source = TreeGrid.DataSource;
var hasChildRows = Source.Where(rec => rec.ParentId == rowTaskId).Count();
if (hasChildRows > 0)
{
if (!this.ExpandCollapseRow)
{
this.TreeGrid.ExpandRow(args.Data); // expanding row on row click by calling ExpandRow method
}
this.ExpandCollapseRow = false;
} else
{
// Logic for only child rows
args.Cancel = true; // prevented rowSelect handlers for child rows
}
}
public void ExpandingHandler(RowExpandingEventArgs<TreeData.BusinessObject> args)
{
// setting flag
this.ExpandCollapseRow = true;
}
public void CollapsingHandler(RowCollapsingEventArgs<TreeData.BusinessObject> args)
{
// setting flag
this.ExpandCollapseRow = true;
}
}
|
Thanks For Your Feedback
ViewTask(ticket.TaskId))" class="mr-1">|
<SfTreeGrid DataSource="@TreeGridData" @ref="TreeGrid" IdMapping="TaskId" ParentIdMapping="ParentId" TreeColumnIndex="1" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<TreeGridEvents CellSelecting="CellSelecting" RowSelecting="RowSelectingHandler" Expanding="ExpandingHandler"
Collapsing="CollapsingHandler" TValue="TreeData.BusinessObject"></TreeGridEvents>
<TreeGridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple" Mode="Syncfusion.Blazor.Grids.SelectionMode.Both" ></TreeGridSelectionSettings>
<TreeGridColumns>
<TreeGridColumn Field="TaskId" HeaderText="Task ID" IsPrimaryKey="true" Width="80" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></TreeGridColumn>
<TreeGridColumn Field="TaskName" HeaderText="Task Name" Width="
</TreeGridColumns>
</SfTreeGrid>
@code{
public List<TreeData.BusinessObject> TreeGridData { get; set; }
SfTreeGrid<TreeData.BusinessObject> TreeGrid { get; set; }
public Boolean ExpandCollapseRow = false;
protected override void OnInitialized()
{
this.TreeGridData = TreeData.GetSelfDataSource().ToList();
}
public void CellSelecting(CellSelectingEventArgs<TreeData.BusinessObject> args)
{
var column = TreeGrid.Columns[Convert.ToInt32(args.CellIndex)].Field; //get the column details and prevent by setting args.Cancel as true on RowSelecting event
} |