Pivot Grid Column Reordering & Moving

    The Pivot Grid component in Ignite UI for Angular provides the Column Moving feature to allow columns reordering via standard drag/drop mouse or touch gestures, or by using the Column Moving API. Column moving works both with pinned and unpinned columns and with Multi-column Headers. Moving a column into the pinned area pins the column and vice versa, moving a column outside of the pinned area unpins the column.

    Note

    Reordering between columns and column groups is allowed only when they are at the same level in the hierarchy and both are in the same group. Moving is allowed between columns/column-groups, if they are top level columns.

    Note

    If a column header is templated and the Column Moving is enabled or the corresponding column is groupable, then the templated elements need to have the draggable attribute set to false! This allows to attach handlers for any event emitted by the element, otherwise the event is consumed by the igxDrag directive.

    Note

    If the pinned area exceeds its maximum allowed width (80% of the total Pivot Grid width), a visual clue notifies the end user that the drop operation is forbidden and pinning is not possible. This means you won't be allowed to drop a column in the pinned area.

    <ng-template igxHeader>
        <igx-icon [attr.draggable]="false" (click)="onClick()"></igx-icon>
    </ng-template>
    

    Angular Pivot Grid Column Moving Overview Example

    Overview

    Column moving feature is enabled on a per-grid level, meaning that the igx-pivot-grid could have either movable or immovable columns. This is done via the moving input of the igx-grid.

    API

    In addition to the drag and drop functionality, the Column Moving feature also provides two API methods to allow moving a column/reordering columns programmatically:

    moveColumn - Moves a column before or after another column (a target). The first parameter is the column to be moved, and the second parameter is the target column. Also accepts an optional third parameter position (representing a DropPosition value), which determines whether to place the column before or after the target column.

    // Move the ID column after the Name column
    const idColumn = grid.getColumnByName("ID");
    const nameColumn = grid.getColumnByName("Name");
    
    grid.moveColumn(idColumn, nameColumn, DropPosition.AfterDropTarget);
    

    move - Moves a column to a specified visible index. If the passed index parameter is invalid (is negative, or exceeds the number of columns), or if the column is not allowed to move to this index (if inside another group), no operation is performed.

    // Move the ID column at 3rd position.
    const idColumn = grid.getColumnByName("ID");
    idColumn.move(3);
    

    Note that when using the API, only the columnMovingEnd event will be emitted, if the operation was successful. Also note that in comparison to the drag and drop functionality, using the API does not require setting the moving property to true.

    Events

    There are several events related to the column moving to provide a means for tapping into the columns' drag and drop operations. These are columnMovingStart, columnMoving and columnMovingEnd. You can subscribe to the columnMovingEnd event of the igx-pivot-grid to implement some custom logic when a column is dropped to a new position. For example, you can cancel dropping the Category after the Change On Year(%) column.

    Styling

    To get started with styling the Pivot Grid column moving headers, we need to import the index file, where all the theme functions and component mixins live:

    @use "igniteui-angular/theming" as *;
    
    // IMPORTANT: Prior to Ignite UI for Angular version 13 use:
    // @import '~igniteui-angular/lib/core/styles/themes/index';
    

    Following the simplest approach, we create a new theme that extends the grid-theme and accepts the $ghost-header-background, $ghost-header-text-color and the $ghost-header-icon-color parameters.

    // Define dark theme for the column moving
    $dark-grid-column-moving-theme: grid-theme(
      $ghost-header-text-color: #f4d45c,
      $ghost-header-background: #575757,
      $ghost-header-icon-color: #f4bb5c
    );
    
    Note

    Instead of hardcoding the color values like we just did, we can achieve greater flexibility in terms of colors by using the palette and color functions. Please refer to Palettes topic for detailed guidance on how to use them.

    The last step is to include the component mixins with its respective theme:

    @include css-vars($dark-grid-column-moving-theme);
    

    Demo

    Note

    The sample will not be affected by the selected global theme from Change Theme.

    API References

    Additional Resources

    Our community is active and always welcoming to new ideas.