Expand mode to be single in Hierarchy grid

Hi,


Could you be so kind as to show me with how to implement this with blazor. ( expand one and collapse other)

Many thanks


3 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team February 4, 2021 02:29 PM UTC

Hi Hugo, 

Greetings from Syncfusion. 

Query: Expand mode to be single in Hierarchy grid - Could you be so kind as to show me with how to implement this with blazor. ( expand one and collapse other). 

We have validated your query and you want to close the detailed row when another detail row is clicked. You can achieve your requirement by using the Microsoft JSInterop and binding the javascript click event to check the current target and then invoking the DetailExpandCollapseRow method of grid. Please find the below code snippet and the sample for your reference. 

[Index.razor] 
<SfGrid @ref="Grid" ID="Grid" DataSource="@Employees" Toolbar="Toolbaritems"> 
    <GridEvents DetailDataBound="DetailDataBound" DataBound="DataBound" TValue="EmployeeData"></GridEvents> 
    <GridTemplates> 
        <DetailTemplate> 
            @{ 
                var employee = (context as EmployeeData); 
                <div> 
                    <SfGrid ID="DetailGrid" DataSource="@Orders"> 
                    . . . 
                    </SfGrid> 
                </div> 
            } 
        </DetailTemplate> 
    </GridTemplates> 
    <GridColumns> 
        . . . 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    SfGrid<EmployeeData> Grid; 
    . . . 
    public bool firstrender { get; set; } = true; 
    public async Task DataBound() 
    { 
        if (firstrender) 
        { 
            var dotNetReference = DotNetObjectReference.Create(this); 
            await Runtime.InvokeAsync<string>("detail", dotNetReference); 
            firstrender = false; 
        } 
    } 
    public async Task DetailDataBound(DetailDataBoundEventArgs<EmployeeData> args) 
    { 
        if (target != null) 
        { 
            if (target == args.Data) 
            { 
                return; 
            } 
            await Grid.DetailExpandCollapseRow(target); 
        } 
        target = args.Data; 
    } 
 
    [JSInvokable("DetailCollapse")] 
    public void DetailRowCollapse() 
    { 
        target = null; 
    } 
    p. . . 
} 

[detailexpand.js] 
function detail(dotnet) { 
    dotnetInstance = dotnet; // dotnet instance to invoke C# method from JS  
} 
 
 
document.addEventListener('click', function (args) { 
    if (args.target.classList.contains("e-dtdiagonaldown") || args.target.classList.contains("e-detailrowexpand")) { 
        dotnetInstance.invokeMethodAsync('DetailCollapse'); // call C# method from javascript function 
    } 
}) 


Please let us know if you have any concerns. 

Regards, 
Rahul 


Marked as answer

HZ Hugo Zhao February 25, 2021 01:43 AM UTC

Thank you very much


RN Rahul Narayanasamy Syncfusion Team February 25, 2021 06:56 AM UTC

Hi Hugo, 
 
Thanks for the update. 
 
Please get back to us if you need further assistance. 
 
Regards, 
Rahul 



Loader.
Up arrow icon