I need to detect if a button within the NodeTempate has been clicked

and that time it should not fire `NodeSelected` events fire. Please see the code below with many omissions for brevity.
stopPropagation not working.


<SfTreeView>

    <TreeViewEvents> NodeSelected="nodeselected" NodeClicked="nodeclicked"> </TreeViewEvents>

    <TreeViewTemplates>

        <NodeTemplate>

            <span @onclick:stopPropagation="true">

                <SfButton @onclick="args => buttonclickevent (args, context)"></SfButton>

            </span>

        </NodeTemplate>

    </TreeViewTemplates>

</SfTreeView>


1 Reply

JA Jafar Ali Shahulhameed Syncfusion Team March 20, 2024 09:58 AM UTC

Hi Sneha,


Based on the shared details we can understand that you are trying to utilize Syncfusion TreeView component. We have prepared the sample aligning with your requirements and achieved your requirements by using the build-in onmousedown events. Kindly refer the code changes below.


<span>

    <SfButton CssClass="newbutton" @onmousedown="@((e) =>buttonclickevent((@context as TreeData).Id))">button</SfButton>

</span>

 

void buttonclickevent(string id)

{

    string[] strArray = new string[] { id };

    TreeView.RemoveNodes(strArray);

}



We have attached the sample for your reference,


Sample: Attached as zip file.


Kindly check out the shared details and get back to us if you need further assistance.


Regards,

Jafar


Attachment: TreeViewEvents_b100473a.zip

Loader.
Up arrow icon