Skip to content

Conversation

@bmsq
Copy link

@bmsq bmsq commented May 29, 2025

Context

core.alter('remove_row') doesn't correctly handle cases where the visual and physical row counts don't match (eg. the table has trimmed rows)

Row removal is eventually handled by DataMap.removeRow(index, amount, source) which uses DataMap.visualRowsToPhysical(visualRowIndex, amount) to convert the passed range of visual rows to an array of physical row indexes.

visualRowsToPhysical() attempts to:

  1. Normalize the passed index and amount parameters based on the size of the table
  2. iterate over each visual row within the normalized visual row index and visual row count
  3. convert the visual row index to its physical equivalent
  4. return array of physical row indexes

The existing logic for step 1 is incorrectly normalizing the passed arguments using the physical number of rows in the columns instead of the visual number of rows. This pull request fixes the normalization to use countRows() instead of countSourceRows(). It also renames the incorrectly named physicRow variable to visualRow since it contains the current visual row index during loop iteration.

How has this been tested?

This has been tested by using verifying the behavior demonstrated by the codesandbox provided with #11643 works as expected regardless of whether the table contains trimmed rows or not.

It is also worth nothing that the fixed normalization logic in visualRowsToPhysical() is now consistent with visualColumnsToPhysical() which provides the same functionality but for columns (although, it too suffers from an incorrectly named physicalCol variable).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature or improvement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Additional language file or change to the existing one (translations)

Related issue(s):

  1. core.alter('remove_row') does not account for trimmed rows #11643

Affected project(s):

  • handsontable
  • @handsontable/angular
  • @handsontable/react
  • @handsontable/react-wrapper
  • @handsontable/vue
  • @handsontable/vue3

Checklist:

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9bee589:

Sandbox Source
handsontable-pr-javascript-demo Configuration
handsontable-ts-demo Configuration
handsontable-pr-react-demo Configuration

@AMBudnik
Copy link
Contributor

Hi @bmsq

Thank you for taking the time to debug the issue, propose a solution, and sign our CLA.

There's one additional thing I would like you to do, though. To push the pull request for developer review, we need to be provided with tests that prove the alteration of the code is correct. Can I ask you to provide those tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants