# Column Headers

> Configure column headers with custom column header, custom sort icon, menu icon and more.

Canonical page: https://infinite-table.com/angular/docs/learn/columns/column-headers

Column headers have the same level of customization as column cells - you can fully control what is being rendered and when. Here's a summary of the things you can do in the column header:

- customize the header label of a column
- specify custom sort icon
- configure and customize the menu icon
- configure the column selection chechbox (for columns configured to display a selection checkbox)
- customize the order of all of the above, and select which ones should be included

## Column Header Label

By default, the label displayed for the column header is the [field](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.field) the column is bound to. If you want to customize this, use the [header](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.header) property.

```tsx
type Developer = {
  id: string;
  firstName: string;
  lastName: string;
  age: number;
};
const columns: InfiniteTablePropColumns<Developer> = {
  id: {
    field: 'id', // will be used as default label in column header
    defaultWidth: 100,
  },
  name: {
    header: 'First and Last Name', // custom column header label
    valueGetter: ({ data }) => `${data.firstName} ${data.lastName}`,
  },
};
```

**Example: Simple table with both default and custom column headers**

```ts
import { Component } from '@angular/core';

import { DataSource, InfiniteTable } from '@infinite-table/infinite-angular';
import type { InfiniteTablePropColumns } from '@infinite-table/infinite-angular';

const columns: InfiniteTablePropColumns<Developer> = {
  id: {
    field: 'id', // will be used as default label in column header
    defaultWidth: 100,
  },
  name: {
    header: 'First and Last Name', // custom column header label
    valueGetter: ({ data }) => `${data.firstName} ${data.lastName}`,
  },
};

type Developer = {
  id: number;
  firstName: string;
  lastName: string;
  age: number;
};

const dataSource = () => {
  return fetch(process.env.NEXT_PUBLIC_BASE_URL + '/developers1k')
    .then((r) => r.json())
    .then((data: Developer[]) => data);
};

const domProps = {
  style: {
    minHeight: 300,
  },
};

@Component({
  selector: 'demo-root',
  imports: [DataSource, InfiniteTable],
  template: `
    <infinite-data-source primaryKey="id" [data]="dataSource">
      <infinite-table
        debugId="column-header-example"
        [domProps]="domProps"
        [columns]="columns"
      />
    </infinite-data-source>
  `,
})
export default class App {
  protected readonly dataSource = dataSource;
  protected readonly columns = columns;
  protected readonly domProps = domProps;
}
```

Having the [header](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.header) property be a strin value is useful but when you want more flexibility, you can use a function instead.

When [the column header](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.header) is a function, it is called with an object that contains the following properties:

- `column` - the current column object. NOTE: it's not the same as the column object you passed to the [columns](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns) prop - but rather an enhanced version of that, which contains additional properties and computed values. It is called a "computed" column - typed as `InfiniteTableComputedColumn<DATA_TYPE>`.
- `columnsMap` - a map of all computed columns available in the table, keyed by the column id. This is useful if at runtime you need access to other columns in the table. NOTE: this map does not contain only the visible columns, but rather ALL the columns.
- `columnSortInfo` - the sorting information for the current column, or `null` if the column is not sorted.
- `api` - a reference to the table [API](https://infinite-table.com/docs/reference/api/index.md) object.
- `columnApi` - a reference to the table [Column API](https://infinite-table.com/docs/reference/column-api/index.md) object for bound to the current column.
- `allRowsSelected: boolean`
- `someRowsSelected: boolean`
- `renderBag` - more on that below - used to reference changes between the different render functions of the column header (those functions are the column header rendering pipeline described in the next section).

All the render props exposed for the rendering pipeline of the column header are called with the same object as the first argument.

Having the [column header](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#column.header) as a function and having access to the state of the column and of the table allows you to create very dynamic column headers that accurately reflect column state.

## Column Header Rendering Pipeline

The rendering pipeline of the column header is similar to the one of the column cells.

It's a series of functions defined on the column that are called while rendering elements found in the column header (the header label, the sort and menu icons, the filtering icon, the selection checkbox).

All of the functions that are part of the column header rendering pipeline are called with the same object as the first argument - the shape of this object is described in the previous section.

- [renderSortIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderSortIcon)
- [renderFilterIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderFilterIcon)
- [renderMenuIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderMenuIcon)
- [renderSelectionCheckBox](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderSelectionCheckBox)
- [renderHeaderSelectionCheckBox](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderHeaderSelectionCheckBox)
- [header](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.header)

If you want to customize any of the above, use the corresponding function.

For even more control, the last function in the pipeline that gets called is the [column.renderHeader](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderHeader) function.

This function is called with the same object as the first argument, but it also has a `renderBag` property that contains the result of all the previous functions in the pipeline (eg: `renderBag.sortIcon` - the result of the [renderSortIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderSortIcon) call, `renderBag.filterIcon` - the result of the [renderFilterIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderFilterIcon) call, etc).

So if you specify a custom [renderHeader](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderHeader) function, it's up to you to use the results of the previous functions in the pipeline, in order to fully take control of the column header.

#### Available properties on the renderBag

The `renderBag` object contains the following properties available to the render functions of the column header:

- `header` - the label of the column header.
- `sortIcon` - the default sort icon
- `filterIcon` - the filter icon - displayed when the current column is used in filtering
- `filterEditor` - the current filter editor
- `menuIcon` - the menu icon that can be clicked to open the column menu
- `selectionCheckBox` - the selection check box - displays the current selection status and controls the selection for all rows.
- `all` - all of the above combined together, as an array.

Each of them is a renderable value (text, a template, a component, or an array of those): show it in a template with `<ng-container [infiniteRender]="renderBag.sortIcon" />` (`InfiniteRender` from `@infinite-table/infinite-angular`).

### Customizing the Sort Icon

For customizing the sort icon, use the [column.renderSortIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderSortIcon) function.

Inside that function you can either use the object passed as a parameter to get information about the sort state of the column

```tsx
renderSortIcon({ columnSortInfo }) {
  if (!columnSortInfo) {
    return ' 🤷‍♂️';
  }
  return columnSortInfo.dir === 1 ? '▲' : '▼';
}
```

or you can return a component (`renderComponent(SortIcon)`) that uses [`injectHeaderCell`](https://infinite-table.com/docs/reference/hooks/index.md#useInfiniteHeaderCell) to get the same information. It returns a signal and has to be called in a field initializer (or the constructor) of a component rendered inside the column header - calling it directly in the `renderSortIcon` function doesn't work.

```ts
import { Component, computed } from '@angular/core';
import {
  injectHeaderCell,
  renderComponent,
} from '@infinite-table/infinite-angular';

/// ...

@Component({
  selector: 'custom-sort-icon',
  template: `{{ icon() }}`,
})
class SortIcon {
  private readonly headerCell = injectHeaderCell();

  protected readonly icon = computed(() => {
    const { columnSortInfo } = this.headerCell();
    if (!columnSortInfo) {
      return ' 🤷‍♂️';
    }
    return columnSortInfo.dir === 1 ? '▲' : '▼';
  });
}

function renderSortIcon() {
  return renderComponent(SortIcon);
}
```

**Example: Custom sort icon for the name column**

```ts
import { Component, computed } from '@angular/core';

import {
  DataSource,
  InfiniteTable,
  injectHeaderCell,
  renderComponent,
} from '@infinite-table/infinite-angular';
import type { InfiniteTablePropColumns } from '@infinite-table/infinite-angular';

@Component({
  selector: 'name-sort-icon',
  template: `{{ icon() }}`,
})
class NameSortIcon {
  
  private readonly headerCell = injectHeaderCell<Developer>();

  protected readonly icon = computed(() => {
    const { columnSortInfo } = this.headerCell();
    if (!columnSortInfo) {
      return ' 🤷‍♂️';
    }
    return columnSortInfo.dir === 1 ? '▲' : '▼';
  });
}

const columns: InfiniteTablePropColumns<Developer> = {
  id: {
    field: 'id', // will be used as default label in column header
    defaultWidth: 100,
  },
  name: {
    header: 'Name', // custom column header label
    valueGetter: ({ data }) => `${data.firstName} ${data.lastName}`,
    renderSortIcon: () => renderComponent(NameSortIcon),
  },
};

type Developer = {
  id: number;
  firstName: string;
  lastName: string;
  age: number;
};

const dataSource = () => {
  return fetch(process.env.NEXT_PUBLIC_BASE_URL + '/developers1k')
    .then((r) => r.json())
    .then((data: Developer[]) => data);
};

const domProps = {
  style: {
    minHeight: 300,
  },
};

@Component({
  selector: 'demo-root',
  imports: [DataSource, InfiniteTable],
  template: `
    <infinite-data-source primaryKey="id" [data]="dataSource">
      <infinite-table
        debugId="column-sort-icon-example"
        [domProps]="domProps"
        [columns]="columns"
      />
    </infinite-data-source>
  `,
})
export default class App {
  protected readonly dataSource = dataSource;
  protected readonly columns = columns;
  protected readonly domProps = domProps;
}
```

### Customizing the Menu Icon

For customizing the menu icon, use the [column.renderMenuIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderMenuIcon) function.

Inside that function you can either use the object passed as a parameter to get information about the column

```tsx
renderMenuIcon({ column }) {
  return `🔧 ${column.id}`;
}
```

or you can return a component (with `renderComponent`) that uses [`injectHeaderCell`](https://infinite-table.com/docs/reference/hooks/index.md#useInfiniteHeaderCell) to get the same information, as a signal.

```ts
import { Component } from '@angular/core';
import {
  injectHeaderCell,
  renderComponent,
} from '@infinite-table/infinite-angular';

/// ...

@Component({
  selector: 'custom-menu-icon',
  template: `🔧 {{ headerCell().column.id }}`,
})
class CustomMenuIcon {
  protected readonly headerCell = injectHeaderCell();
}

function renderMenuIcon() {
  return renderComponent(CustomMenuIcon);
}
```

Hover over the header for the `Name` and `Age` columns to see the custom menu icon.

Also, the id column has `renderMenuIcon: false` set, so it doesn't show a column menu at all.

**Example: Custom menu icon for the name and age columns**

```ts
import { Component, TemplateRef, viewChild } from '@angular/core';

import { DataSource, InfiniteTable } from '@infinite-table/infinite-angular';
import type { InfiniteTablePropColumns } from '@infinite-table/infinite-angular';

type Developer = {
  id: number;
  firstName: string;
  lastName: string;
  age: number;
};

const dataSource = () => {
  return fetch(process.env.NEXT_PUBLIC_BASE_URL + '/developers1k')
    .then((r) => r.json())
    .then((data: Developer[]) => data);
};

const domProps = {
  style: {
    minHeight: 300,
  },
};

@Component({
  selector: 'demo-root',
  imports: [DataSource, InfiniteTable],
  template: `
    <infinite-data-source primaryKey="id" [data]="dataSource">
      <infinite-table
        debugId="column-menu-icon-example"
        [domProps]="domProps"
        [columns]="columns"
      />
    </infinite-data-source>

    <ng-template #globe>
      <div>🌎</div>
    </ng-template>
  `,
})
export default class App {
  protected readonly dataSource = dataSource;
  protected readonly domProps = domProps;

  private readonly globeTemplate =
    viewChild.required<TemplateRef<unknown>>('globe');

  protected readonly columns: InfiniteTablePropColumns<Developer> = {
    id: {
      field: 'id',
      defaultWidth: 80,
      renderMenuIcon: false,
    },

    name: {
      header: 'Name', // custom column header label
      valueGetter: ({ data }) => `${data.firstName} ${data.lastName}`,

      // custom menu icon
      renderMenuIcon: () => this.globeTemplate(),
    },
    age: {
      field: 'age',
      header: 'Age',
      renderMenuIcon: ({ column }) => {
        return `🔧 ${column.id}`;
      },
    },
  };
}
```

If you don't want to show a column menu (icon) at all, you can set the [column.renderMenuIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderMenuIcon) prop to `false`.

Also, see the [column.renderMenuIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderMenuIcon) docs for an example on how to use the api to open the column menu.

### Customizing the Filter Icon

For customizing the filter icon, use the [column.renderFilterIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderFilterIcon) function.

Inside that function you can either use the object passed as a parameter to get information about the `filtered` state of the column

```tsx
renderFilterIcon({ filtered }) {
  return filtered ? '🔍' : '';
}
```

or you can return a component (with `renderComponent`) that uses [`injectHeaderCell`](https://infinite-table.com/docs/reference/hooks/index.md#useInfiniteHeaderCell) to get the same information, as a signal.

```ts
import { Component } from '@angular/core';
import {
  injectHeaderCell,
  renderComponent,
} from '@infinite-table/infinite-angular';

/// ...

@Component({
  selector: 'custom-filter-icon',
  template: `{{ headerCell().filtered ? '🔥' : '' }}`,
})
class CustomFilterIcon {
  protected readonly headerCell = injectHeaderCell();
}

function renderFilterIcon() {
  return renderComponent(CustomFilterIcon);
}
```

In addition, you can use the `filtered` property in the [column.header](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.header) function to determine if the column is filtered or not and render a different header label.

If specified, the [column.renderFilterIcon](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderFilterIcon) function prop is called even if the column is not currently filtered.

The `salary` column will show a bolded label when filtered.

The `firstName` column will show a custom filter icon when filtered.

**Example: Custom filter icons for salary and name columns**

```ts
import { Component, TemplateRef, viewChild } from '@angular/core';

import { DataSource, InfiniteTable } from '@infinite-table/infinite-angular';
import type {
  DataSourceData,
  DataSourcePropFilterValue,
  InfiniteTablePropColumns,
} from '@infinite-table/infinite-angular';

type Developer = {
  id: number;
  firstName: string;
  lastName: string;

  currency: string;
  preferredLanguage: string;
  stack: string;
  canDesign: 'yes' | 'no';

  salary: number;
};

const data: DataSourceData<Developer> = () => {
  return fetch(process.env.NEXT_PUBLIC_BASE_URL + `/developers1k-sql?`)
    .then((r) => r.json())
    .then((data: Developer[]) => data);
};

const domProps = {
  style: {
    height: '100%',
  },
};

@Component({
  selector: 'demo-root',
  imports: [DataSource, InfiniteTable],
  template: `
    <infinite-data-source
      [data]="data"
      primaryKey="id"
      [defaultFilterValue]="defaultFilterValue"
      [filterDelay]="0"
    >
      <infinite-table
        debugId="column-filter-icon-example"
        [domProps]="domProps"
        [columnDefaultWidth]="150"
        [columnMinWidth]="50"
        [columns]="columns"
      />
    </infinite-data-source>

    <ng-template #boldSalary>
      <b>Salary</b>
    </ng-template>
  `,
})
export default class App {
  protected readonly data = data;
  protected readonly domProps = domProps;
  protected readonly defaultFilterValue: DataSourcePropFilterValue<Developer> =
    [];

  private readonly boldSalaryTemplate =
    viewChild.required<TemplateRef<unknown>>('boldSalary');

  protected readonly columns: InfiniteTablePropColumns<Developer> = {
    id: {
      field: 'id',
      type: 'number',
      defaultWidth: 100,
    },
    salary: {
      field: 'salary',
      type: 'number',
      header: ({ filtered }) => {
        return filtered ? this.boldSalaryTemplate() : 'Salary';
      },

      renderFilterIcon: () => {
        return null;
      },
    },

    firstName: {
      field: 'firstName',
      renderFilterIcon: ({ filtered }) => {
        return filtered ? '🔥' : '';
      },
    },
    stack: { field: 'stack' },
    currency: { field: 'currency' },
  };
}
```

#### Changing the display of filters

Infinite Table allows very deep cusstomization of the column header, including the filters.

For example, you might not want to display the column filters under the column header, but rather in a separate menu popover.

This section shows how to do that. You can use [showColumnFilters=false](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#showColumnFilters) to hide the filters from under the column header.

Next, you can use the [column.renderHeader](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderHeader) function to render a custom filter icon that opens a filter popover when clicked.

You don't need to re-implement the filter editor, you have acces to it via the `renderBag.filterEditor` property. The code below shows how to do this.

**Example: Custom display of column filters**

```ts
import {
  Component,
  EmbeddedViewRef,
  OnDestroy,
  TemplateRef,
  ViewContainerRef,
  inject,
  signal,
  viewChild,
} from '@angular/core';

import {
  DataSource,
  InfiniteRender,
  InfiniteTable,
  alignNode,
  injectHeaderCell,
  injectInfinitePortalContainer,
  renderComponent,
} from '@infinite-table/infinite-angular';
import type {
  DataSourceData,
  DataSourcePropFilterValue,
  DataSourcePropShouldReloadDataObject,
  InfiniteTablePropColumns,
} from '@infinite-table/infinite-angular';

type Developer = {
  id: number;
  firstName: string;
  lastName: string;

  currency: string;
  preferredLanguage: string;
  stack: string;
  canDesign: 'yes' | 'no';

  salary: number;
};

const data: DataSourceData<Developer> = () => {
  return fetch(process.env.NEXT_PUBLIC_BASE_URL + `/developers1k-sql?`)
    .then((r) => r.json())
    .then((data: Developer[]) => data);
};

@Component({
  selector: 'column-filter-menu-icon',
  imports: [InfiniteRender],
  host: {
    '(mousedown)': 'markInsideMenu($event)',
    '(pointerdown)': 'toggle($event)',
  },
  template: `
    <svg
      xmlns="http://www.w3.org/2000/svg"
      width="16"
      height="16"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
    >
      <polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"></polygon>
    </svg>

    
    <ng-template #popup>
      <!-- not inside this component's element, so its events don't reach the host listeners: it gets the same ones -->
      <div
        (mousedown)="markInsideMenu($event)"
        (pointerdown)="toggle($event)"
        style="position: absolute; color: white; top: 0; left: 0; overflow: visible; background: var(--infinite-background); border: var(--infinite-cell-border); padding: 10px"
        [style.width.px]="headerCell().column.computedWidth"
        [style.display]="visible() ? 'block' : 'none'"
      >
        <ng-container [infiniteRender]="headerCell().renderBag.filterEditor" />
      </div>
    </ng-template>
  `,
})
class ColumnFilterMenuIcon implements OnDestroy {
  protected readonly headerCell = injectHeaderCell();
  private readonly portalContainer = injectInfinitePortalContainer();
  private readonly vcr = inject(ViewContainerRef);
  private readonly popupTemplate =
    viewChild.required<TemplateRef<unknown>>('popup');

  protected readonly visible = signal(false);

  private popup: EmbeddedViewRef<unknown> | null = null;

  protected markInsideMenu(event: MouseEvent) {
    // @ts-ignore
    event.__insideMenu = this.headerCell().column.id;
  }

  protected toggle(event: PointerEvent) {
    const { column } = this.headerCell();

    event.stopPropagation();

    if (this.visible()) {
      this.visible.set(false);
      return;
    }

    this.show();

    const handleMouseDown = (event: MouseEvent) => {
      // @ts-ignore
      if (event.__insideMenu !== column.id) {
        this.visible.set(false);
        document.documentElement.removeEventListener(
          'mousedown',
          handleMouseDown,
        );
      }
    };
    document.documentElement.addEventListener('mousedown', handleMouseDown);
  }

  private show() {
    const container = this.portalContainer();
    if (!container) {
      return;
    }
    if (!this.popup) {
      this.popup = this.vcr.createEmbeddedView(this.popupTemplate());
    }
    this.visible.set(true);
    this.popup.detectChanges();

    const [node] = this.popup.rootNodes as HTMLDivElement[];
    container.appendChild(node);

    const alignTo = this.headerCell().htmlElementRef.current;
    if (alignTo) {
      alignNode(node, {
        alignTo,
        alignPosition: [['TopRight', 'BottomRight']],
      });
    }
  }

  ngOnDestroy() {
    this.popup?.destroy();
  }
}

// what React renders as a fragment: the host is `display: contents`, so its
// children are laid out by the header
@Component({
  selector: 'custom-header-with-filter-menu',
  imports: [InfiniteRender, ColumnFilterMenuIcon],
  host: { style: 'display: contents' },
  template: `
    <ng-container [infiniteRender]="headerCell().renderBag.header" />
    <div style="flex: 1"></div>

    <ng-container [infiniteRender]="headerCell().renderBag.filterIcon" />

    <ng-container [infiniteRender]="headerCell().renderBag.menuIcon" />
    <column-filter-menu-icon />
  `,
})
class CustomHeaderWithFilterMenu {
  protected readonly headerCell = injectHeaderCell();
}

const columns: InfiniteTablePropColumns<Developer> = {
  id: {
    field: 'id',
    type: 'number',
    defaultWidth: 100,
    renderHeader: () => renderComponent(CustomHeaderWithFilterMenu),
  },
  salary: {
    field: 'salary',
    type: 'number',
    renderHeader: () => renderComponent(CustomHeaderWithFilterMenu),
  },

  firstName: {
    field: 'firstName',
    renderHeader: () => renderComponent(CustomHeaderWithFilterMenu),
  },
  stack: { field: 'stack', renderHeader: () => renderComponent(CustomHeaderWithFilterMenu) },
  currency: { field: 'currency', renderHeader: () => renderComponent(CustomHeaderWithFilterMenu) },
};

@Component({
  selector: 'demo-root',
  imports: [DataSource, InfiniteTable],
  template: `
    <infinite-data-source
      [data]="data"
      primaryKey="id"
      [defaultFilterValue]="defaultFilterValue"
      [shouldReloadData]="shouldReloadData"
    >
      <infinite-table
        debugId="custom-column-filter-display-example"
        [showColumnFilters]="false"
        [columnDefaultWidth]="150"
        [columnMinWidth]="50"
        [columns]="columns"
      />
    </infinite-data-source>
  `,
})
export default class App {
  protected readonly data = data;
  protected readonly columns = columns;
  protected readonly defaultFilterValue: DataSourcePropFilterValue<Developer> =
    [];
  protected readonly shouldReloadData: DataSourcePropShouldReloadDataObject<Developer> =
    {
      filterValue: false,
      sortInfo: false,
      groupBy: false,
      pivotBy: false,
    };
}
```

### Customizing the Selection Checkbox

For customizing the selection checkbox in the column header, use the [column.renderHeaderSelectionCheckBox](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderHeaderSelectionCheckBox) function.

If you want another column, other than the group column, to show a selection checkbox, you have to also set the [column.renderSelectionCheckBox](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns.renderSelectionCheckBox) prop to `true`.

The group column, as well as the `stack` column display a custom selection checkbox in the column header.

**Example: Custom header checkbox selection for columns**

```ts
import { Component, TemplateRef, viewChild } from '@angular/core';

import {
  DataSource,
  InfiniteRender,
  InfiniteTable,
} from '@infinite-table/infinite-angular';
import type {
  DataSourcePropGroupBy,
  InfiniteTablePropColumns,
  InfiniteTablePropGroupColumn,
} from '@infinite-table/infinite-angular';

const defaultGroupBy: DataSourcePropGroupBy<Developer> = [
  {
    field: 'canDesign',
  },
  {
    field: 'stack',
  },
  {
    field: 'preferredLanguage',
  },
];

const domProps = {
  style: {
    flex: 1,
    minHeight: 500,
  },
};

const dataSource = () => {
  return fetch(process.env.NEXT_PUBLIC_BASE_URL + '/developers100')
    .then((r) => r.json())
    .then((data: Developer[]) => data);
};

type Developer = {
  id: number;
  firstName: string;
  lastName: string;
  country: string;
  city: string;
  currency: string;
  email: string;
  preferredLanguage: string;
  stack: string;
  canDesign: 'yes' | 'no';
  hobby: string;
  salary: number;
  age: number;
};

@Component({
  selector: 'demo-root',
  imports: [DataSource, InfiniteTable, InfiniteRender],
  template: `
    <infinite-data-source
      [data]="dataSource"
      [groupBy]="defaultGroupBy"
      selectionMode="multi-row"
      primaryKey="id"
    >
      <infinite-table
        debugId="column-header-selection-checkbox-example"
        [columns]="columns"
        [domProps]="domProps"
        [groupColumn]="groupColumn"
        [columnDefaultWidth]="150"
      />
    </infinite-data-source>

    
    <ng-template #decoratedCheckBox let-renderBag="renderBag">
      <b>[<ng-container [infiniteRender]="renderBag.selectionCheckBox" />]</b>
    </ng-template>
  `,
})
export default class App {
  protected readonly dataSource = dataSource;
  protected readonly defaultGroupBy = defaultGroupBy;
  protected readonly domProps = domProps;

  private readonly decoratedCheckBox =
    viewChild.required<TemplateRef<unknown>>('decoratedCheckBox');

  protected readonly columns: InfiniteTablePropColumns<Developer> = {
    country: {
      field: 'country',
    },
    firstName: {
      field: 'firstName',
      defaultHiddenWhenGroupedBy: '*',
    },
    stack: {
      renderSelectionCheckBox: true,
      renderHeaderSelectionCheckBox: () => this.decoratedCheckBox(),
      field: 'stack',
    },
    age: { field: 'age' },
    id: { field: 'id' },
    preferredLanguage: {
      field: 'preferredLanguage',
    },
    canDesign: {
      field: 'canDesign',
    },
  };

  protected readonly groupColumn: InfiniteTablePropGroupColumn<Developer> = {
    field: 'firstName',
    renderHeaderSelectionCheckBox: () => this.decoratedCheckBox(),
    defaultWidth: 300,
  };
}
```
