# 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:** react  **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/react/js/grid-column-template.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-react-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.jsx

```jsx
import { GridComponent, ColumnsDirective, ColumnDirective, Inject, Page } from '@syncfusion/ej2-react-grids';
import { orderDetails } from '../datasource/grid-data';

const palette = ['#6366f1', '#0ea5e9', '#10b981', '#f59e0b', '#ec4899', '#8b5cf6'];
const colorFor = (text) => palette[[...text].reduce((sum, ch) => sum + ch.charCodeAt(0), 0) % palette.length];
const initials = (name) => name.trim().split(/\s+/).map((p) => p[0]).slice(0, 2).join('').toUpperCase();
const daysToShip = (o) => Math.max(0, Math.round((new Date(o.ShippedDate) - new Date(o.OrderDate)) / 86400000));
const statusOf = (days) => (days <= 5 ? { label: 'Fast', color: '#059669', bg: '#d1fae5' }
  : days <= 10 ? { label: 'On time', color: '#0369a1', bg: '#e0f2fe' }
  : { label: 'Delayed', color: '#b45309', bg: '#fef3c7' });

const idStyle = { fontFamily: 'monospace', fontSize: 12, background: '#f1f5f9', color: '#334155', padding: '4px 8px', borderRadius: 6 };
const avatarStyle = { width: 38, height: 38, borderRadius: 12, color: '#fff', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', fontWeight: 600, fontSize: 13 };
const stackStyle = { display: 'flex', flexDirection: 'column', justifyContent: 'center' };
const mainLine = { display: 'block', color: '#0f172a', lineHeight: '20px' };
const subLine = { display: 'block', fontSize: 12, color: '#94a3b8', lineHeight: '16px' };
const chipStyle = { borderRadius: 999, padding: '2px 10px', fontSize: 12, fontWeight: 600 };

function ColumnTemplate() {
  const orderTemplate = (p) => <span style={idStyle}>#{p.OrderID}</span>;
  const customerTemplate = (p) => {
    const name = p.CustomerName.trim();
    return (
      <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
        <span style={{ ...avatarStyle, background: colorFor(p.CustomerID) }}>{initials(name)}</span>
        <div style={stackStyle}>
          <span style={{ ...mainLine, fontWeight: 600 }}>{name}</span>
          <span style={subLine}>{p.CustomerID}</span>
        </div>
      </div>
    );
  };
  const destinationTemplate = (p) => (
    <div style={stackStyle}>
      <span style={mainLine}>{p.ShipCity}</span>
      <span style={subLine}>{p.ShipCountry}</span>
    </div>
  );
  const statusTemplate = (p) => {
    const days = daysToShip(p);
    const s = statusOf(days);
    return <span style={{ ...chipStyle, background: s.bg, color: s.color }}>{s.label} · {days}d</span>;
  };

  return (
    <div className='control-pane'>
      <div className='control-section'>
        <GridComponent dataSource={orderDetails} height='440' rowHeight={64} allowPaging={true}
          pageSettings={{ pageSize: 8 }} gridLines='Horizontal'>
          <ColumnsDirective>
            <ColumnDirective field='OrderID' headerText='Order' width='110' template={orderTemplate} isPrimaryKey={true} />
            <ColumnDirective field='CustomerName' headerText='Customer' width='220' template={customerTemplate} />
            <ColumnDirective field='ShipCity' headerText='Destination' width='150' template={destinationTemplate} />
            <ColumnDirective headerText='Status' width='150' template={statusTemplate} />
            <ColumnDirective field='Freight' headerText='Freight' width='120' format='C2' textAlign='Right' />
          </ColumnsDirective>
          <Inject services={[Page]} />
        </GridComponent>
      </div>
    </div>
  );
}
export default ColumnTemplate;
```
