angular-ui/ui-grid

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

Open

#5,728 opened on 2016年10月6日

GitHub で見る
 (0 comments) (0 reactions) (0 assignees)JavaScript (5,395 stars) (2,496 forks)batch import
good first issue

説明

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.

コントリビューターガイド