# grid-column-template

> Data grid with a column template that renders each customer as an avatar with initials, a tinted color, and a delivery status badge.

**Framework:** javascript  **Component:** Grid  **Variant:** column-template

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/javascript/grid-column-template.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-grids
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/grid-column-template/grid.html

```html
<div class="control-section">
    <div class="content-wrapper">
        <div id="container"></div>
    </div>
</div>
```

### src/components/grid-column-template/grid.ts

```typescript
import { Grid, Page } from '@syncfusion/ej2-grids';
import { orderData } from '../datasource/grid-data';

Grid.Inject(Page);

const palette: string[] = ['#6366f1', '#0ea5e9', '#10b981', '#f59e0b', '#ec4899', '#8b5cf6'];

function prepare(): Object[] {
    return (orderData as any[]).map((o: any) => {
        const days: number = Math.max(0, Math.round((new Date(o.ShippedDate).getTime() - new Date(o.OrderDate).getTime()) / 86400000));
        const s = days <= 5 ? { label: 'Fast', color: '#059669', bg: '#d1fae5' }
            : days <= 10 ? { label: 'On time', color: '#0369a1', bg: '#e0f2fe' }
            : { label: 'Delayed', color: '#b45309', bg: '#fef3c7' };
        return {
            ...o,
            Initials: o.ShipName.trim().split(/\s+/).map((p: string) => p[0]).slice(0, 2).join('').toUpperCase(),
            Color: palette[[...o.CustomerID].reduce((sum: number, c: string) => sum + c.charCodeAt(0), 0) % palette.length],
            StatusText: s.label + ' · ' + days + 'd', StatusColor: s.color, StatusBg: s.bg
        };
    });
}

export function initColumnTemplateGrid(): void {
    const orderTemplate: string = '<span style="font-family:monospace;font-size:12px;background:#f1f5f9;color:#334155;padding:4px 8px;border-radius:6px">#${OrderID}</span>';
    const customerTemplate: string =
        '<div style="display:flex;align-items:center;gap:12px">' +
        '<span style="background:${Color};width:38px;height:38px;border-radius:12px;color:#fff;display:inline-flex;align-items:center;justify-content:center;font-weight:600;font-size:13px">${Initials}</span>' +
        '<div style="display:flex;flex-direction:column;justify-content:center">' +
        '<span style="display:block;font-weight:600;color:#0f172a;line-height:20px">${ShipName}</span>' +
        '<span style="display:block;font-size:12px;color:#94a3b8;line-height:16px">${CustomerID}</span></div></div>';
    const destinationTemplate: string =
        '<div style="display:flex;flex-direction:column;justify-content:center">' +
        '<span style="display:block;color:#0f172a;line-height:20px">${ShipCity}</span>' +
        '<span style="display:block;font-size:12px;color:#94a3b8;line-height:16px">${ShipCountry}</span></div>';
    const statusTemplate: string =
        '<span style="background:${StatusBg};color:${StatusColor};border-radius:999px;padding:2px 10px;font-size:12px;font-weight:600">${StatusText}</span>';

    const grid: Grid = new Grid({
        dataSource: prepare(),
        height: 440,
        rowHeight: 64,
        allowPaging: true,
        pageSettings: { pageSize: 8 },
        gridLines: 'Horizontal',
        columns: [
            { field: 'OrderID', headerText: 'Order', width: 110, template: orderTemplate, isPrimaryKey: true },
            { field: 'ShipName', headerText: 'Ship To', width: 240, template: customerTemplate },
            { field: 'ShipCity', headerText: 'Destination', width: 150, template: destinationTemplate },
            { headerText: 'Status', width: 150, template: statusTemplate },
            { field: 'Freight', headerText: 'Freight', width: 120, format: 'C2', textAlign: 'Right' }
        ]
    });
    grid.appendTo('#container');
}
```
