DataGrid Column Resizing

Resize DataGrid columns from the header with explicit widths, min widths, and auto-fit behavior.

Column Resizing

Drag column edges or auto-fit columns to the grid width

Column resizing is disabled by default. Turn it on with [resizable]="true" and set an explicit width on each column. Drag the handle on a header edge to resize. Use minResizableWidth / maxResizableWidth to limit how far a column can grow or shrink. When columns are narrower than the grid, empty space remains on the right until you auto-fit.

Live example

The Product column is limited between 180px and 420px. Other columns resize freely (minimum 50px).

Loading interactive DataGrid example…

Configuration

OptionScopeDescription
[resizable]GridEnables header drag handles. Default false.
ColumnDef.widthColumnRequired (px) for every visible column when resizing is on.
minResizableWidthColumnMinimum width while dragging (defaults to 50).
maxResizableWidthColumnMaximum width while dragging.
ColumnDef.resizableColumnSet false to disable resizing for one column.
autoFitColumnsToGrid()Grid API Expands or shrinks all visible data columns evenly so their total width matches the grid viewport.

Column resizing

Integration steps

  1. Set [resizable]="true" on ngb-datagrid. Resizing is disabled by default.
  2. Give every visible column an explicit width in pixels.
  3. Optionally set minResizableWidth and maxResizableWidth on ColumnDef to limit drag range.
  4. Drag the handle on the right edge of a header cell to resize that column.
  5. When total column width is less than the grid width, the table leaves whitespace on the right.
  6. Call grid.autoFitColumnsToGrid() after data is loaded to expand or shrink columns to fill the viewport.

Component

      @Component({
  imports: [Datagrid],
  template: `
    <button type="button" class="btn btn-outline-primary btn-sm" (click)="autoFitToGrid()">
      Auto-fit Columns to Grid
    </button>

    <ngb-datagrid
      #productGrid
      [columns]="columns"
      [data]="rows"
      [resizable]="true"
      [enableSorting]="true"
      [scrollable]="true"
    ></ngb-datagrid>
  `,
})
export class ProductGridResizeDemo {
  @ViewChild('productGrid') grid?: Datagrid<ProductRow>;

  readonly columns: ColumnDef<ProductRow>[] = [
    { field: 'sku', header: 'SKU', width: 120 },
    { field: 'product', header: 'Product', width: 260, minResizableWidth: 180, maxResizableWidth: 420 },
    { field: 'category', header: 'Category', width: 160 },
    { field: 'price', header: 'Price', type: 'number', width: 120 },
  ];

  autoFitToGrid(): void {
    this.grid?.autoFitColumnsToGrid();
  }
}
    

Declarative column limits

      <ngb-grid-column
  field="product"
  header="Product"
  [width]="260"
  [minResizableWidth]="180"
  [maxResizableWidth]="420"
></ngb-grid-column>
    

This project is not affiliated with ng-bootstrap or ngx-bootstrap. Those projects focus mainly on Bootstrap components for Angular. ngbootstrap focuses on Angular UI for data-heavy apps, especially Data Grid, Angular-native Form Builder, drag and drop workflows, documentation examples, and performance-focused Angular patterns.