TreeList view selection and expanding icon glued together issue.

1 Answer 66 Views
TreeList
SAm
Top achievements
Rank 1
SAm asked on 19 Jul 2023, 04:24 PM | edited on 20 Jul 2023, 02:33 PM

I am trying to separate the selection and the expanding icon. 

Current issue: When I click on expand icon it also selects the data item

Desired result: Expanding should not select the data  item. Clicking on the expand icon and selecting the data item should be separate.

7q6hqt (forked) - StackBlitz

How can I separate them ?

 

Please help

Thank you so much

Filip
Telerik team
commented on 20 Jul 2023, 12:44 PM

Hi, Sam,

I tried to open the sent example, however, it led me to Stackblitz's home page instead of the intended example. 

Can you please fork the sample again and share the forked link so that I can investigate further?

Regards,
Filip
SAm
Top achievements
Rank 1
commented on 20 Jul 2023, 02:33 PM

Sorry about that, I have updated the question.
SAm
Top achievements
Rank 1
commented on 20 Jul 2023, 02:34 PM

So for u try bascially cliking on the expand icon 2-4 times and you will see that it automatically selects the row of the data. I want to separate these two things.

1 Answer, 1 is accepted

Sort by
0
Filip
Telerik team
answered on 24 Jul 2023, 12:11 PM

Hi, Sam,

Thank you for the provided updated response with a visual representation and for the additional information.

While there is no inbuilt functionality for separating the selection from the icon expansion, this can be achieved by using the cellRender and making a check if the click occurs on the icon or not and preventing the selection

I have prepared an example that showcases this approach:

https://stackblitz.com/edit/react-ykx6az-gxqnpb?file=app%2Fmain.tsx

  const cellRender = (td, props) => {
    const handleClick = (ev) => {
      // Check if the click occurred on the expand arrow
      if (
        ev.target.classList.contains('k-icon') ||
        ev.target.classList.contains('k-i-expand')
      ) {
        ev.preventDefault();
      } else {
        props.selectionChange(ev);
      }
    };
    return <td {...td.props} onClick={handleClick} />;
  };

This way the selection will not occur when the arrow is expanded or collapsed and only when an item has been selected.

Regards,
Filip
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources!

Tags
TreeList
Asked by
SAm
Top achievements
Rank 1
Answers by
Filip
Telerik team
Share this question
or