Skip to content

Bảng & DataTable ​

Table tạo kiểu cho bảng thường (sọc, hover, viền, gọn, bảng màu). DataTable là component đầy đủ: sắp xếp, tìm kiếm, phân trang, chọn dòng, ẩn cột theo màn hình, sửa trực tiếp và chế độ phía server — mọi chữ đều được dịch.

Bảng thường ​

Bảng thường
vue
<ThlTable striped hover>
  <thead><tr><th>#</th><th>Name</th><th>Role</th><th>Office</th></tr></thead>
  <tbody><tr v-for="e in rows" :key="e.id"><td>{{ e.id }}</td><td>{{ e.name }}</td><td>{{ e.role }}</td><td>{{ e.office }}</td></tr></tbody>
</ThlTable>
tsx
<SimpleTable striped hover>
  <thead>…</thead><tbody>…</tbody>
</SimpleTable>
html
<table thlTable striped hover>
  <thead>…</thead><tbody>…</tbody>
</table>

DataTable ​

DataTable
vue
<div><p v-if="selected.length">Selected: {{ selected.map((r) => r.name).join(', ') }}</p>
<ThlDataTable :data="employees" :columns="columns" row-key="id" selectable striped :page-size="5" @selection-change="(r) => (selected = r)">
  <template #cell-name="{ row }"><div class="thl-flex" style="flex-wrap:nowrap"><ThlAvatar :src="row.avatar" size="xs" />{{ row.name }}</div></template>
  <template #cell-joined="{ row }">{{ d(row.joined) }}</template>
  <template #cell-salary="{ row }">{{ n(row.salary, { style: 'currency', currency: 'USD' }) }}</template>
</ThlDataTable></div>
tsx
<DataTable data={employees} rowKey="id" selectable striped pageSize={5} onSelectionChange={setSelected}
  columns={[
    { key: 'name', title: t('pages.contact.name'), sortable: true,
      render: (e) => <><Avatar src={e.avatar} size="xs" />{e.name}</> },
    { key: 'office', title: 'Office', sortable: true, hideBelow: 1024 },
    { key: 'salary', title: 'Salary', sortable: true, align: 'right',
      render: (e) => t.n(e.salary, { style: 'currency', currency: 'USD' }) },
  ]} />
html
<thl-data-table [data]="employees" [columns]="columns" rowKey="id" selectable [striped]="true" [pageSize]="5"
                (selectionChange)="selected.set($event)">
  <ng-template thlCell="name" let-row><thl-avatar [src]="row.avatar" size="xs" />{{ row.name }}</ng-template>
  <ng-template thlCell="salary" let-row>{{ i18n.n(row.salary, { style: 'currency', currency: 'USD' }) }}</ng-template>
</thl-data-table>

Cột ​

TrườngKiểuMô tả
keystringTên trường (và tên slot ô cell-{key} / thlCell="{key}")
titlestring / nodeTiêu đề cột
value(row) => unknownHàm lấy giá trị để sắp xếp/tìm kiếm (mặc định row[key])
sortablebooleanBấm tiêu đề để sắp xếp tăng → giảm → bỏ
compare(a, b) => numberHàm so sánh tuỳ biến
searchablebooleanCó tham gia tìm kiếm chung không (mặc định true)
align'left' | 'center' | 'right'
widthstring | number
hideBelownumber (px)Ẩn cột dưới độ rộng này
editablebooleanSửa trực tiếp → sự kiện cell-edit
renderchỉ ReactHàm render ô

Chế độ phía server ​

Đặt manual và total, rồi tải dữ liệu khi có sự kiện query-change ({ page, pageSize, sort, search }):

vue
<ThlDataTable manual :total="total" :data="rows" :columns="cols" :loading="loading" @query-change="load" />

API ​

Table

<ThlTable> · import { ThlTable } from '@thl-ui/vue'

PropKiểuMặc định
stripedboolean—
hoverboolean—
borderedany—
compactboolean—
colorstring—
fullstring—

Slot: default

DataTable

<ThlDataTable> · import { ThlDataTable } from '@thl-ui/vue'

PropKiểuMặc định
data*array—
columns*array—
rowKeyany—
pageSizenumber—
paginatebooleantrue
searchablebooleantrue
selectableboolean—
stripedboolean—
hoverboolean—
borderedboolean—
colorstring—
stackboolean—
compactboolean—
emptyTextstring—
manualboolean—
totalnumber—
loadingboolean—

Sự kiện: selection-changecell-editquery-change

Slot: toolbarcell-{key}