Treeview nodes not selected do not re render

1 Answer 71 Views
TreeView
Nick
Top achievements
Rank 1
Nick asked on 25 Oct 2022, 08:03 AM

Hi All

I have a TreeView, the nodes dont seem to call a re render unless the node is selected. Is this the case and if so, can it be altered or are there work arounds?

To replicate, I have created a conditionally rendered functional component as the node item format:

Below is the component that renders each node

 const fetchTreeItemView = (props) => {

        let item: TreeViewDataItem = props.item;

        return (
            <>
                {(item.selected) &&
                    <TreeUnselectedEntityNode treeItem={item} />
                }
               {(!item.selected) &&
                    <TreeUnselectedEntityNode treeItem={item} />
                }
            </>
        );
    };

This calls the below component:


export const TreeUnselectedAttribute = props => {
    const [visibleDialog, setVisibleDialog] = React.useState<boolean>(false);
    const MENU_ID = `cm-${props.treeItem.index}`;
    const { show } = useContextMenu({
        id: MENU_ID,
    });

    const handleClickRemove = (e: React.MouseEvent) => {
        show(e);
    }

    const handleRemoveClick = (e) => {
        props.onRemoveTreeItem(props.treeItem);
    }

    const handleClick = (e) => {
    }

    const handleClickShowAttributeSelectDialog = (e) => {
        setVisibleDialog(true);
    }

    const hideAttributeSelectDialog = () => {
        setVisibleDialog(false);
    };

    return (
        <>
            <div>
                <div onContextMenu={handleClickRemove}>
                    <span key="0" /> {props.treeItem.branchXmlNode.name}
                </div>
                <Menu id={MENU_ID} theme={theme.dark}>
                    <Item onClick={handleRemoveClick}>Remove</Item>
                    <Separator />
                    <Submenu label="Add">
                        <Item onClick={handleClickShowAttributeSelectDialog}>Attribute</Item>
                    </Submenu>
                </Menu>
                {visibleDialog ? <div>Tester</div> : <div>another tester</div>}
            </div>
        </>
    );
}

Its the same component called either way if the node is selected or not, but if the node is selected, when 

visibleDialog 

is changed, the contents of the div changes (rerenders). if its not selected then no matter how the value of 

visibleDialog 

is changed, it does not update (rerender)

 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 27 Oct 2022, 07:05 AM

Hi Nick,

Changing the "visibleDialog" value will only make changes to the already rendered item. If you want to force the re-rendering of the entire TreeView you can either use its key property and manually change it (to force re-mounting) or make some change in a state variable connected with the TreeView.

If further assistance is needed, could you please modify the following example so it can demonstrate the exact problem that you are facing and what is the expected behavior:

 

Regards,
Konstantin Dikov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TreeView
Asked by
Nick
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or