Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,10 @@ const select = (val: any[], active: any) => {
TreeToFlatten([active])
.filter((item: any) => item.id != active.id)
.forEach((item: any) => {
multipleTableRef.value?.toggleRowSelection(item, true)
if (multipleSelection.value.some((select) => item.id == select.id)) {
multipleTableRef.value?.toggleRowSelection(item, true)
}
})

multipleSelection.value = multipleTableRef.value.getSelectionRows()
} else {
multipleSelection.value = val
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code you've provided is mostly correct with some minor optimizations and improvements:

  1. Simplified Condition: The condition inside the if statement can be simplified to directly check if an item exists in multipleSelection. This avoids iterating over the entire array twice.

Here's your updated code with this optimization:

const select = (val: any[], active: any) => {
  TreeToFlatten([active])
    .filter((item: any) => item.id !== active.id)
    .forEach((item: any) => {
      const isSelected = multipleSelection.value.some(s => s.id === item.id);
      
      // Toggle row selection only if it is not already selected
      if (!isSelected && multipleTableRef.value)
        multipleTableRef.value.toggleRowSelection(item, true);
    });

  multipleSelection.value = multipleTableRef.value.getSelectionRows();
};

Key Improvements:

  • Single Iteration Check: Reduced the need for filtering out items that cannot exist in multipleSelection.
  • Direct Selection Check: Use some() to check if an item is already selected without needing to iterate further through multipleSelection.

These changes make the function more efficient while maintaining its functionality.

Expand Down
Loading