[expandrow.js]
|
var prevrowIndex;
document.addEventListener('click', function (args) {
if (args.target.classList.contains("e-dtdiagonalright") || args.target.classList.contains("e-detailrowcollapse")) {
var gObj = document.getElementById("Grid").ej2_instances[0];
if (prevrowIndex != undefined) {
gObj.detailRowModule.collapse(prevrowIndex); //Collapse only the particular row instead based on previous index
}
prevrowIndex = parseInt(args.target.closest("tr").getAttribute("aria-rowindex")); //Get the previously expanded row index
}
})
|
var prevrowIndex;
document.addEventListener('click', function (args) {
if (args.target.classList.contains("e-dtdiagonalright") || args.target.classList.contains("e-detailrowcollapse")) {
var gObj = document.getElementsByClassName("e-grid")[0].blazor__instance;
if (prevrowIndex != undefined) {
var rowele = gObj.getRowByIndex(prevrowIndex).querySelector(".e-detailrowexpand");
rowele.click();
}
prevrowIndex = parseInt(args.target.closest("tr").getAttribute("aria-rowindex"));
}
})
|
<GridEvents DetailDataBound="DetailDataBound" TValue="EmployeeData"></GridEvents>
|
public bool firstrender { get; set; } = true;
public async Task DataBound()
{
if (firstrender)
{
var dotNetReference = DotNetObjectReference.Create(this); // create dotnet ref
await Runtime.InvokeAsync<string>("detail", dotNetReference); // send the dotnet ref to JS side
firstrender = false;
}
}
public async Task DetailDataBound(DetailDataBoundEventArgs<EmployeeData> args)
{
if (target != null)
{
if (target == args.Data) // return when target is equal to args.data
{
return;
}
await Grid.DetailExpandCollapseRow(target);
}
target = args.Data;
}
[JSInvokable("DetailCollapse")] // method called from JS when collapse is done
public void DetailRowCollapse()
{
target = null; // empty the target when collapse action is done
}
[detailexpand.js]
|
Must check target is not the same or you cannot open or close the same item
private SfGrid<Evaluation> grid;
private Evaluation target;
public async Task DetailDataBound(DetailDataBoundEventArgs<Evaluation> args)
{
// Must check target is not the same or you cannot open or close the same item
if (target != null && target.Id != args.Data.Id)
{
await grid.ExpandCollapseDetailRowAsync(target);
}
target = args.Data;
}
Hi Fermin,
Thanks for the suggestion.