Grid row selection doesn't work correctly if its detail cell is a grid

1 Answer 32 Views
Grid
Jie
Top achievements
Rank 3
Iron
Iron
Iron
Jie asked on 09 Dec 2024, 08:23 PM

Hi,

Please see example https://codesandbox.io/p/sandbox/dry-tdd-9hqysc?file=%2Fapp%2Fapp.tsx

The example shows a master grid with selection enabled. Master grid contains a detail grid which also have selection enabled. The problem is, when clicking a row in detail grid, the selection in master grid changes, and the detail grid's selection doesn't change.

 

Thanks,

Jie

 

1 Answer, 1 is accepted

Sort by
0
Yanko
Telerik team
answered on 11 Dec 2024, 05:23 PM

Hi, Jie,

When selection is enabled for both parent and detail grid you need to implement separate functions for the `onSelectionChenge` event to select the rows accordingly. Also when the detail row is clicked the parent row is also clicked. Therefore you need to include logic to determine whether the selection event was invoked from the detail or the parent component:

//parent grid onSelectionChange  
const onSelectionChange = (event) => {
    let targetEl = event.nativeEvent.target;
    let isDetail = false;
    while (targetEl.tagName != 'BODY') {
      if (targetEl.tagName == 'TR') {
        if (targetEl.className.indexOf('k-detail-row') >= 0) {
          isDetail = true;
          break;
        }
      }
      targetEl = targetEl.parentNode;
    }
    if (!isDetail) {
     //selection logic
    }
  };

I prepared an example that displays a Master Detail Grid with enabled selection for both the master and the detail grids:

If any inquiries arise on the topic please let me know.

Regards,
Yanko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Jie
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Yanko
Telerik team
Share this question
or