# grid-detail-template

> Data grid with a detail row template that expands a row to reveal the shipped order lines and totals beneath it.

**Framework:** javascript  **Component:** Grid  **Variant:** detail-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-detail-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-detail-template/grid.html

```html
<div class="control-section">
    <div class="content-wrapper">
        <div id="container"></div>
    </div>
</div>
<script id="detailtemplate" type="text/x-template">
    <div style="display:grid;grid-template-columns:1.2fr 1fr 1fr;gap:16px;padding:16px 24px;background:#f8fafc">
        <div style="background:#fff;border:1px solid #e2e8f0;border-radius:12px;padding:16px">
            <h5 style="margin:0 0 12px;font-size:11px;letter-spacing:.06em;text-transform:uppercase;color:#64748b">Shipment timeline</h5>
            <div style="display:flex;align-items:flex-start;gap:12px;margin-bottom:14px">
                <span style="width:10px;height:10px;margin-top:5px;border-radius:50%;background:#6366f1;box-shadow:0 0 0 4px #e0e7ff;flex-shrink:0"></span>
                <div>
                    <div style="font-weight:600;color:#0f172a">Order placed</div>
                    <div style="font-size:12px;color:#64748b">${OrderDateText}</div>
                </div>
            </div>
            <div style="display:flex;align-items:flex-start;gap:12px">
                <span style="width:10px;height:10px;margin-top:5px;border-radius:50%;background:#6366f1;box-shadow:0 0 0 4px #e0e7ff;flex-shrink:0"></span>
                <div>
                    <div style="font-weight:600;color:#0f172a">Shipped</div>
                    <div style="font-size:12px;color:#64748b">${ShippedDateText} · ${Days} days after order</div>
                </div>
            </div>
        </div>
        <div style="background:#fff;border:1px solid #e2e8f0;border-radius:12px;padding:16px">
            <h5 style="margin:0 0 12px;font-size:11px;letter-spacing:.06em;text-transform:uppercase;color:#64748b">Delivery address</h5>
            <div style="font-weight:600;color:#0f172a">${ShipName}</div>
            <div style="color:#475569;margin-top:4px">${ShipAddress}</div>
            <div style="color:#475569">${ShipCity}, ${ShipCountry}</div>
        </div>
        <div style="background:#fff;border:1px solid #e2e8f0;border-radius:12px;padding:16px">
            <h5 style="margin:0 0 12px;font-size:11px;letter-spacing:.06em;text-transform:uppercase;color:#64748b">Freight charge</h5>
            <div style="font-size:28px;font-weight:700;color:#0f172a">${FreightText}</div>
            <div style="font-size:12px;color:#64748b;margin-top:4px">Customer ${CustomerID}</div>
        </div>
    </div>
</script>
```

### src/components/grid-detail-template/grid.ts

```typescript
import { Grid, Page, DetailRow } from '@syncfusion/ej2-grids';
import { orderData } from '../datasource/grid-data';

Grid.Inject(Page, DetailRow);

const fmt = (d: any): string => new Date(d).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' });

function prepare(): Object[] {
    return (orderData as any[]).map((o: any) => ({
        ...o,
        Days: Math.max(0, Math.round((new Date(o.ShippedDate).getTime() - new Date(o.OrderDate).getTime()) / 86400000)),
        OrderDateText: fmt(o.OrderDate),
        ShippedDateText: fmt(o.ShippedDate),
        FreightText: '$' + Number(o.Freight).toFixed(2)
    }));
}

export function initDetailTemplateGrid(): void {
    const grid: Grid = new Grid({
        dataSource: prepare(),
        height: 460,
        allowPaging: true,
        pageSettings: { pageSize: 8 },
        gridLines: 'Horizontal',
        detailTemplate: '#detailtemplate',
        columns: [
            { field: 'OrderID', headerText: 'Order', width: 110, isPrimaryKey: true },
            { field: 'ShipName', headerText: 'Ship To', width: 240 },
            { field: 'ShipCity', headerText: 'City', width: 160 },
            { field: 'ShipCountry', headerText: 'Country', width: 150 },
            { field: 'Freight', headerText: 'Freight', width: 120, format: 'C2', textAlign: 'Right' }
        ]
    });
    grid.appendTo('#container');
}
```
