Table
Apply responsive styles to a native HTML table.
Invoice | Status | Method | Amount |
---|---|---|---|
INV001 | Paid | Credit Card | $250.00 |
INV002 | Pending | PayPal | $150.00 |
INV003 | Unpaid | Bank Transfer | $350.00 |
INV004 | Paid | Credit Card | $450.00 |
INV005 | Paid | PayPal | $550.00 |
INV006 | Pending | Bank Transfer | $200.00 |
INV007 | Unpaid | Credit Card | $300.00 |
Total | $2,500.00 |
import { Component } from '@angular/core';
import { HlmTableImports } from '@spartan-ng/helm/table';
@Component({
selector: 'spartan-table-preview',
imports: [...HlmTableImports],
host: {
class: 'w-full overflow-x-auto',
},
template: `
<table hlmTable>
<caption hlmCaption>A list of your recent invoices.</caption>
<thead hlmTHead>
<tr hlmTr>
<th hlmTh class="w-[100px]">Invoice</th>
<th hlmTh>Status</th>
<th hlmTh>Method</th>
<th hlmTh class="text-right">Amount</th>
</tr>
</thead>
<tbody hlmTBody>
@for (invoice of _invoices; track invoice.invoice) {
<tr hlmTr>
<td hlmTd class="font-medium">{{ invoice.invoice }}</td>
<td hlmTd>{{ invoice.paymentStatus }}</td>
<td hlmTd>{{ invoice.paymentMethod }}</td>
<td hlmTd class="text-right">{{ invoice.totalAmount }}</td>
</tr>
}
</tbody>
<tfoot hlmTFoot>
<tr hlmTr>
<td hlmTd [attr.colSpan]="3">Total</td>
<td hlmTd class="text-right">$2,500.00</td>
</tr>
</tfoot>
</table>
`,
})
export class TablePreview {
protected _invoices = [
{
invoice: 'INV001',
paymentStatus: 'Paid',
totalAmount: '$250.00',
paymentMethod: 'Credit Card',
},
{
invoice: 'INV002',
paymentStatus: 'Pending',
totalAmount: '$150.00',
paymentMethod: 'PayPal',
},
{
invoice: 'INV003',
paymentStatus: 'Unpaid',
totalAmount: '$350.00',
paymentMethod: 'Bank Transfer',
},
{
invoice: 'INV004',
paymentStatus: 'Paid',
totalAmount: '$450.00',
paymentMethod: 'Credit Card',
},
{
invoice: 'INV005',
paymentStatus: 'Paid',
totalAmount: '$550.00',
paymentMethod: 'PayPal',
},
{
invoice: 'INV006',
paymentStatus: 'Pending',
totalAmount: '$200.00',
paymentMethod: 'Bank Transfer',
},
{
invoice: 'INV007',
paymentStatus: 'Unpaid',
totalAmount: '$300.00',
paymentMethod: 'Credit Card',
},
];
}
Installation
npx nx g @spartan-ng/cli:ui table
ng g @spartan-ng/cli:ui table
Usage
import { HlmTableImports } from '@spartan-ng/helm/table';
<table hlmTable>
<caption hlmCaption>A list of your recent invoices.</caption>
<thead hlmTHead>
<tr hlmTr>
<th hlmTh class="w-[100px]">Invoice</th>
<th hlmTh>Status</th>
<th hlmTh>Method</th>
<th hlmTh class="text-right">Amount</th>
</tr>
</thead>
<tbody hlmTBody>
@for (invoice of _invoices; track invoice.invoice) {
<tr hlmTr>
<td hlmTd class="font-medium">{{ invoice.invoice }}</td>
<td hlmTd>{{ invoice.paymentStatus }}</td>
<td hlmTd>{{ invoice.paymentMethod }}</td>
<td hlmTd class="text-right">{{ invoice.totalAmount }}</td>
</tr>
}
</tbody>
<tfoot hlmTFoot>
<tr hlmTr>
<td hlmTd [attr.colSpan]="3">Total</td>
<td hlmTd class="text-right">$2,500.00</td>
</tr>
</tfoot>
</table>
Helm API
HlmTable
Selector: table[hlmTable]
Inputs
Prop | Type | Default | Description |
---|---|---|---|
hlmTable | Partial<HlmTableVariant> | string | {} | Input to configure the variant of the table, this input has the highest priority. |
class | ClassValue | - | - |
HlmTHead
Selector: thead[hlmTHead]
Inputs
Prop | Type | Default | Description |
---|---|---|---|
class | ClassValue | - | - |
HlmTBody
Selector: tbody[hlmTBody]
Inputs
Prop | Type | Default | Description |
---|---|---|---|
class | ClassValue | - | - |
HlmTFoot
Selector: tfoot[hlmTFoot]
Inputs
Prop | Type | Default | Description |
---|---|---|---|
class | ClassValue | - | - |
HlmTr
Selector: tr[hlmTr]
Inputs
Prop | Type | Default | Description |
---|---|---|---|
class | ClassValue | - | - |
HlmTh
Selector: th[hlmTh]
Inputs
Prop | Type | Default | Description |
---|---|---|---|
class | ClassValue | - | - |
HlmTd
Selector: td[hlmTd]
Inputs
Prop | Type | Default | Description |
---|---|---|---|
class | ClassValue | - | - |
HlmCaption
Selector: caption[hlmCaption]
Inputs
Prop | Type | Default | Description |
---|---|---|---|
class | ClassValue | - | - |
Data Table
For more complex tables, have a look at the data table , which is powered by the incredible work of TanStack-Table
.
See the Data Table documentation for more information.