Skip to content

moveColumn doesn't account for non-movable columns at beginning of columns array #5728

@jeffrpowell

Description

@jeffrpowell

Please make sure each of the following is true before submitting a new issue. We are a small team with limited time and it is very difficult to manage issues if they aren't reported correctly.

  • This is a bug report, not a question on how to use the grid.
    Use Stack Overflow or Gitter for questions.
  • You have searched the open issues to see if this bug has been filed before. We don't want duplicate issues.
  • You have reviewed the tutorials and documentation to ensure you are using the grid correctly. ui-grid.info
  • You are using the latest version of the grid. Older versions are not patched or supported.
  • You have provided steps to recreate your bug. A plunkr is even better.

If you have grouping enabled on a grid, moving columns will break when you try to move things to or from the end of the list. This is because a new invisible treeBaseHeader column is prepended to the list of columns, which is classified as a "nonMovableColumn" in the uiGridMoveColumnService.

Given the following example scenario...

  • table with 7 columns, including the treeBaseHeader, and the last 3 columns are invisible.
    • with 'Y' meaning a movable column and 'N' non-movable, the columns array looks like [N, Y, Y, Y, N, N, N]
  • moving column from position 1 to position 3
    • I'm assuming this should be considered a valid move

...here's where the error occurs in the moveColumn function:

if (originalPosition >= (columns.length - nonMovableColumns) || finalPosition >= (columns.length - nonMovableColumns)) {
    gridUtil.logError('MoveColumn: Invalid values for originalPosition, finalPosition');
    return;
}

That if-statement evaluates to if (1 >= (7 - 4) || 3 >= (7 - 4)). Since 3 >= (7-4), we get a false-positive error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions