Data table
Data table แสดงข้อมูลเป็นแถวและคอลัมน์ (Carbon DataTable) web component ทำตาม Carbon web components (cds-table): คุณเขียนตารางเป็น element — <ui-table-head> ที่มีหัวคอลัมน์ และ <ui-table-body> ที่มีแถวของเซลล์ — แล้วตารางจะเรียงลำดับ ค้นหา เลือก ขยาย และแบ่งหน้าแถวที่อยู่ในตัวมัน นอกจากที่ Carbon มี ยังซ่อนและตรึงคอลัมน์ ส่งออก CSV แก้ไขเซลล์ในตาราง และปรับความกว้างคอลัมน์ได้ ส่วน DataTable ของ React + Tailwind ขับเคลื่อนด้วยข้อมูล: คุณส่ง headers และ rows ให้
ย้ายมาจาก <ui-data-table> (ก่อน 1.0)? ดูการย้ายไป 1.0
สัญญา
สัญญาที่ยังมีผลของฝ่ายกฎหมาย
สัญญา
คู่สัญญา
สถานะ
แก้ไขล่าสุด
สัญญาบริการ บริษัท เอซีเอ็ม จำกัด ลงนามแล้ว 2026-09-30
สัญญารักษาความลับ โกลเบ็กซ์ ฉบับร่าง 2026-10-01
ต่อสัญญาเช่า อินิเทค กำลังตรวจ 2026-09-12
สัญญาบริการหลัก อัมเบรลลา ลงนามแล้ว 2026-08-21
HTML React React + Tailwind <ui-table >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-header-description slot ="description" >สัญญาที่ยังมีผลของฝ่ายกฎหมาย</ui-table-header-description >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >สัญญา</ui-table-header-cell >
<ui-table-header-cell >คู่สัญญา</ui-table-header-cell >
<ui-table-header-cell >สถานะ</ui-table-header-cell >
<ui-table-header-cell >แก้ไขล่าสุด</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row >
<ui-table-cell >สัญญาบริการ</ui-table-cell ><ui-table-cell >บริษัท เอซีเอ็ม จำกัด</ui-table-cell ><ui-table-cell >ลงนามแล้ว</ui-table-cell ><ui-table-cell >2026-09-30</ui-table-cell >
</ui-table-row >
<ui-table-row >
<ui-table-cell >สัญญารักษาความลับ</ui-table-cell ><ui-table-cell >โกลเบ็กซ์</ui-table-cell ><ui-table-cell >ฉบับร่าง</ui-table-cell ><ui-table-cell >2026-10-01</ui-table-cell >
</ui-table-row >
<ui-table-row >
<ui-table-cell >ต่อสัญญาเช่า</ui-table-cell ><ui-table-cell >อินิเทค</ui-table-cell ><ui-table-cell >กำลังตรวจ</ui-table-cell ><ui-table-cell >2026-09-12</ui-table-cell >
</ui-table-row >
<ui-table-row >
<ui-table-cell >สัญญาบริการหลัก</ui-table-cell ><ui-table-cell >อัมเบรลลา</ui-table-cell ><ui-table-cell >ลงนามแล้ว</ui-table-cell ><ui-table-cell >2026-08-21</ui-table-cell >
</ui-table-row >
</ui-table-body >
</ui-table >
const headers = [
{ key: 'name' , header: 'สัญญา' },
{ key: 'party' , header: 'คู่สัญญา' },
{ key: 'status' , header: 'สถานะ' },
{ key: 'updated' , header: 'แก้ไขล่าสุด' },
];
const rows = [
{ id: '1' , name: 'สัญญาบริการ' , party: 'บริษัท เอซีเอ็ม จำกัด' , status: 'ลงนามแล้ว' , updated: '2026-09-30' },
{ id: '2' , name: 'สัญญารักษาความลับ' , party: 'โกลเบ็กซ์' , status: 'ฉบับร่าง' , updated: '2026-10-01' },
{ id: '3' , name: 'ต่อสัญญาเช่า' , party: 'อินิเทค' , status: 'กำลังตรวจ' , updated: '2026-09-12' },
{ id: '4' , name: 'สัญญาบริการหลัก' , party: 'อัมเบรลลา' , status: 'ลงนามแล้ว' , updated: '2026-08-21' },
];
// หัวคอลัมน์และเซลล์ของแถว ใช้ซ้ำในตัวอย่างข้างล่าง
const headerCells = headers.map ((h) => <UiTableHeaderCell key = {h.key} column = {h.key}>{h.header}</UiTableHeaderCell >);
const cells = (row: Record <string , string >) => headers.map ((h) => <UiTableCell key = {h.key}>{row[h.key]}</UiTableCell >);
<UiTable >
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableHeaderDescription slot = "description" >สัญญาที่ยังมีผลของฝ่ายกฎหมาย</UiTableHeaderDescription >
<UiTableHead >
<UiTableHeaderRow >{headerCells}</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => <UiTableRow key = {row.id}>{cells (row)}</UiTableRow >)}
</UiTableBody >
</UiTable >
<DataTable heading = "สัญญา" description = "สัญญาที่ยังมีผลของฝ่ายกฎหมาย" headers = {headers} rows = {rows} />
headers และ rows เป็นข้อมูลชุดเดียวกันทุกเวอร์ชัน: HTML เขียนออกมาเป็น element ตัวอย่าง React ข้างล่าง map ด้วย headerCells และ cells(row) จากด้านบน ส่วน React + Tailwind รับเป็น prop
ติดตั้ง
npm shadcn · Web component shadcn · React + Tailwind คัดลอกเอง npm install @purpurabog/ui
npx shadcn@4 add @kanok-ui/table
npx shadcn@4 add @kanok-ui/tw-data-table
# Web component
# 1. ติดตั้ง dependency
npm install lit@^3.3.0
# 2. คัดลอก "content" ของแต่ละไฟล์จาก
# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/table.json
# ไปไว้ที่ target ของมัน:
# components/ui/primitives/table/defs.ts
# components/ui/primitives/table/table-batch-actions.ts
# components/ui/primitives/table/table-body.ts
# components/ui/primitives/table/table-cell.ts
# components/ui/primitives/table/table-column-resize.ts
# components/ui/primitives/table/table-column-settings.ts
# components/ui/primitives/table/table-column.styles.ts
# components/ui/primitives/table/table-csv-export.ts
# components/ui/primitives/table/table-expanded-row.ts
# components/ui/primitives/table/table-grid.ts
# components/ui/primitives/table/table-head.ts
# components/ui/primitives/table/table-header-cell.ts
# components/ui/primitives/table/table-header-description.ts
# components/ui/primitives/table/table-header-row.ts
# components/ui/primitives/table/table-header-title.ts
# components/ui/primitives/table/table-row.ts
# components/ui/primitives/table/table-skeleton.ts
# components/ui/primitives/table/table-toolbar-action.styles.ts
# components/ui/primitives/table/table-toolbar-content.ts
# components/ui/primitives/table/table-toolbar-search.ts
# components/ui/primitives/table/table-toolbar.ts
# components/ui/primitives/table/table.styles.ts
# components/ui/primitives/table/table.ts
# 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json):
# button, checkbox, core-column-resize, core-csv, core-grid, core-table, pagination, popover, radio, search, shared-element, shared-events, shared-field, shared-localize, shared-skeleton, tooltip, tokens
# React + Tailwind
# 1. ติดตั้ง dependency
npm install @purpurabog/ui@^2.3.0
# 2. คัดลอก "content" ของแต่ละไฟล์จาก
# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-data-table.json
# ไปไว้ที่ target ของมัน:
# components/ui/react-tw/data-table.tsx
# components/ui/react-tw/data-table-pins.ts
# components/ui/react-tw/data-table.styles.ts
# 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json):
# core-grid, core-table, tw-checkbox, tw-data-table-columns, tw-data-table-csv, tw-data-table-grid, tw-data-table-parts, tw-data-table-resize, tw-data-table-skeleton, tw-dom, tw-i18n, tw-pagination, tw-refs, tw-theme, tw-utils
npm ให้ทุก component จากแพ็กเกจ ส่วน shadcn คัดลอกซอร์สเข้าแอปของคุณแทน เป็นสำเนาที่ล็อกเวอร์ชันนี้และแก้เองได้ คำสั่ง shadcn ต้องตั้ง registry @kanok-ui ใน components.json ครั้งเดียวก่อน ดู ติดตั้ง
วิธีใช้
HTML React React + Tailwind <script type ="module" >
import '@purpurabog/ui/table' ;
</script >
<ui-table aria-label ="สัญญา" >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >สัญญา</ui-table-header-cell >
<ui-table-header-cell >สถานะ</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row >
<ui-table-cell >สัญญาบริการ</ui-table-cell >
<ui-table-cell >ลงนามแล้ว</ui-table-cell >
</ui-table-row >
</ui-table-body >
</ui-table >
import { UiTable, UiTableHead, UiTableHeaderRow, UiTableHeaderCell, UiTableBody, UiTableRow, UiTableCell } from '@purpurabog/ui/react' ;
<UiTable aria-label = "สัญญา" >
<UiTableHead >
<UiTableHeaderRow >
<UiTableHeaderCell >สัญญา</UiTableHeaderCell >
<UiTableHeaderCell >สถานะ</UiTableHeaderCell >
</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
<UiTableRow >
<UiTableCell >สัญญาบริการ</UiTableCell >
<UiTableCell >ลงนามแล้ว</UiTableCell >
</UiTableRow >
</UiTableBody >
</UiTable >
import { DataTable } from '@/components/ui/react-tw/data-table' ;
<DataTable
heading = "สัญญา"
headers = {[{ key: 'name' , header: 'สัญญา' }, { key: 'status' , header: 'สถานะ' }]}
rows = {[{ id: '1' , name: 'สัญญาบริการ' , status: 'ลงนามแล้ว' }]}
/>
@purpurabog/ui/table ประกาศ element ui-table* ทุกตัว <ui-table> มี <ui-table-head> ที่มี <ui-table-header-row> หนึ่งแถวของ <ui-table-header-cell> และ <ui-table-body> ที่มี <ui-table-row> ของ <ui-table-cell> คอลัมน์ของเซลล์คือลำดับของมันในแถว ชื่อตาราง คำอธิบาย และ toolbar ใส่ใน slot title, description และ toolbar ของตาราง ตารางทำงานกับแถวที่เจอในตัว: เพิ่ม ลบ หรือสลับลำดับแถวแล้วตารางตามให้เอง ใน React + Tailwind header แต่ละตัวคือ { key, header } และแถวแต่ละแถวต้องมี id ที่ไม่เปลี่ยน
เซลล์แบบกำหนดเอง
เซลล์แสดงอะไรก็ได้ที่ใส่ไว้ในนั้น: ตัวเลขที่จัดรูปแบบแล้ว ลิงก์ หรือ tag การเรียงลำดับอ่าน sort-value ของเซลล์ถ้ามี (ให้จำนวนเงินที่แสดงเป็น "1,250,000" มีค่าตัวเลขล้วน) และการส่งออก CSV อ่าน csv-value ถ้าไม่มีทั้งสองอย่างจะใช้ข้อความในเซลล์ ส่วนการค้นหาอ่านข้อความ
สัญญา
สัญญา
จำนวนเงิน (บาท)
สถานะ
สัญญาบริการ
1,250,000
ลงนามแล้ว
สัญญารักษาความลับ
0
ฉบับร่าง
ต่อสัญญาเช่า
480,000
กำลังตรวจ
HTML React React + Tailwind <ui-table >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >สัญญา</ui-table-header-cell >
<ui-table-header-cell >จำนวนเงิน (บาท)</ui-table-header-cell >
<ui-table-header-cell >สถานะ</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row >
<ui-table-cell >สัญญาบริการ</ui-table-cell >
<ui-table-cell sort-value ="1250000" csv-value ="1250000" >1,250,000</ui-table-cell >
<ui-table-cell ><ui-tag size ="sm" type ="green" >ลงนามแล้ว</ui-tag ></ui-table-cell >
</ui-table-row >
<ui-table-row >
<ui-table-cell >สัญญารักษาความลับ</ui-table-cell >
<ui-table-cell sort-value ="0" csv-value ="0" >0</ui-table-cell >
<ui-table-cell ><ui-tag size ="sm" type ="gray" >ฉบับร่าง</ui-tag ></ui-table-cell >
</ui-table-row >
<ui-table-row >
<ui-table-cell >ต่อสัญญาเช่า</ui-table-cell >
<ui-table-cell sort-value ="480000" csv-value ="480000" >480,000</ui-table-cell >
<ui-table-cell ><ui-tag size ="sm" type ="blue" >กำลังตรวจ</ui-tag ></ui-table-cell >
</ui-table-row >
</ui-table-body >
</ui-table >
const tagTypes = { 'ลงนามแล้ว' : 'green' , 'ฉบับร่าง' : 'gray' , 'กำลังตรวจ' : 'blue' } as const ;
<UiTable >
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableHead >
<UiTableHeaderRow >{headerCells}</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => (
<UiTableRow key = {row.id}>
<UiTableCell >{row.name}</UiTableCell >
<UiTableCell sort-value = {String (row.amount)} csv-value = {String (row.amount)}>{row.amount.toLocaleString ('th-TH' )}</UiTableCell >
<UiTableCell ><UiTag size = "sm" type = {tagTypes[row.status]}>{row.status}</UiTag ></UiTableCell >
</UiTableRow >
))}
</UiTableBody >
</UiTable >
import { Tag } from '@/components/ui/react-tw/tag' ;
const tagTypes = { 'ลงนามแล้ว' : 'green' , 'ฉบับร่าง' : 'gray' , 'กำลังตรวจ' : 'blue' } as const ;
<DataTable
heading = "สัญญา"
headers = {headers}
rows = {rows}
renderCell = {(row, header) => {
if (header.key === 'amount' ) return Number (row.amount).toLocaleString ('th-TH' );
if (header.key === 'status' ) return <Tag size = "sm" type = {tagTypes[row.status as keyof typeof tagTypes]}>{String (row.status)}</Tag >;
return String (row[header.key]);
}}
/>
React + Tailwind render เซลล์ด้วย renderCell(row, header) ซึ่งคืน React node และ align: 'end' บน header ชิดเซลล์ของคอลัมน์นั้นไปด้านท้าย การเรียงลำดับและการค้นหาใช้ค่าดิบ
การเรียงลำดับ
is-sortable บนตารางให้หัวคอลัมน์ทุกตัวมีปุ่มเรียง ส่วน is-sortable บนหัวคอลัมน์บางตัวทำให้เรียงได้เฉพาะตัวนั้น (attribute ของตารางตั้งให้หัวคอลัมน์ทุกตัว) การกดแต่ละครั้งเลื่อน sort-direction ของหัวคอลัมน์ไปตาม sort-cycle (ค่าเริ่มต้น none → ascending → descending → none) หัวคอลัมน์อื่นกลับเป็น none แล้วตารางย้ายแถวตามลำดับนั้น ตัวเลขเรียงตามค่า ข้อความเรียงตาม locale (ค่าเริ่มต้นคือ lang ของหน้า) และ none คืนลำดับเดิมของแถว หัวคอลัมน์ที่มี sort-direction ใน markup จะเรียงแถวตอนโหลด หัวคอลัมน์ยิง ui-table-header-cell-sort ที่ยกเลิกได้พร้อม { oldSortDirection, sortDirection } ก่อนย้ายแถว และตารางยิง ui-table-sorted พร้อม { sortedHeader } หลังย้าย
สัญญา
สัญญา
คู่สัญญา
จำนวนเงิน (บาท)
แก้ไขล่าสุด
สัญญาบริการ บริษัท เอซีเอ็ม จำกัด 1,250,000 2026-09-30
สัญญารักษาความลับ โกลเบ็กซ์ 0 2026-10-01
ต่อสัญญาเช่า อินิเทค 480,000 2026-09-12
สัญญาบริการหลัก อัมเบรลลา 9,800,000 2026-08-21
การเรียง: amount, descending
HTML React React + Tailwind <ui-table id ="table-sort" >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell column ="name" is-sortable >สัญญา</ui-table-header-cell >
<ui-table-header-cell column ="party" >คู่สัญญา</ui-table-header-cell >
<ui-table-header-cell column ="amount" is-sortable sort-direction ="descending" >จำนวนเงิน (บาท)</ui-table-header-cell >
<ui-table-header-cell column ="updated" is-sortable >แก้ไขล่าสุด</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row >
<ui-table-cell >สัญญาบริการ</ui-table-cell ><ui-table-cell >บริษัท เอซีเอ็ม จำกัด</ui-table-cell ><ui-table-cell sort-value ="1250000" >1,250,000</ui-table-cell ><ui-table-cell >2026-09-30</ui-table-cell >
</ui-table-row >
<ui-table-row >
<ui-table-cell >สัญญารักษาความลับ</ui-table-cell ><ui-table-cell >โกลเบ็กซ์</ui-table-cell ><ui-table-cell sort-value ="0" >0</ui-table-cell ><ui-table-cell >2026-10-01</ui-table-cell >
</ui-table-row >
<ui-table-row >
<ui-table-cell >ต่อสัญญาเช่า</ui-table-cell ><ui-table-cell >อินิเทค</ui-table-cell ><ui-table-cell sort-value ="480000" >480,000</ui-table-cell ><ui-table-cell >2026-09-12</ui-table-cell >
</ui-table-row >
<ui-table-row >
<ui-table-cell >สัญญาบริการหลัก</ui-table-cell ><ui-table-cell >อัมเบรลลา</ui-table-cell ><ui-table-cell sort-value ="9800000" >9,800,000</ui-table-cell ><ui-table-cell >2026-08-21</ui-table-cell >
</ui-table-row >
</ui-table-body >
</ui-table >
<p >การเรียง: <output id ="table-sort-out" >amount, descending</output ></p >
<script type ="module" >
const table = document.getElementById ('table-sort' );
table.addEventListener ('ui-table-sorted' , (event) => {
const { column, sortDirection } = event.detail.sortedHeader;
document.getElementById ('table-sort-out' ).value = `${ column }, ${ sortDirection }` ;
});
</script >
import type { TableSortDirection } from '@purpurabog/ui' ;
const [sort, setSort] = useState <{ column: string ; direction: TableSortDirection }>({ column: '' , direction: 'none' });
const sorted = sortRows (rows, sort); // เรียงเอง หรือให้ server เรียง
<UiTable >
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableHead >
<UiTableHeaderRow >
{headers.map ((h) => (
<UiTableHeaderCell
key = {h.key}
column = {h.key}
sortDirection = {sort.column === h.key ? sort.direction : 'none' }
onUiTableHeaderCellSort = {(e) => {
e.preventDefault (); // React render แถวเอง ตารางต้องไม่ย้ายแถว
setSort ({ column: h.key, direction: e.detail.sortDirection });
}}
>
{h.header}
</UiTableHeaderCell >
))}
</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{sorted.map ((row) => <UiTableRow key = {row.id}>{cells (row)}</UiTableRow >)}
</UiTableBody >
</UiTable >
<p >การเรียง: <output >{sort.column}, {sort.direction}</output ></p >
const [sort, setSort] = useState <DataTableSort >({ key: 'amount' , direction: 'descending' });
<DataTable heading = "สัญญา" sortable sortKey = {sort.key} sortDirection = {sort.direction} onSortChange = {setSort} headers = {headers} rows = {rows} />
<p >การเรียง: <output >{sort.key}, {sort.direction}</output ></p >
ตารางเรียงลำดับด้วยการย้ายแถวใน DOM แถวที่ framework render (React, Vue, Angular) เป็นของ framework นั้น จึงต้องเรียก preventDefault() ใน ui-table-header-cell-sort เรียงข้อมูลเอง (หรือให้ server เรียง) render แถวตามลำดับนั้น แล้วตั้ง sort-direction (sortDirection) ของหัวคอลัมน์ แบบในแท็บ React เปลี่ยนวิธีเปรียบเทียบได้ด้วยการกำหนด customSortRow(lhs, rhs, collator) บนตาราง React + Tailwind รับ defaultSortKey / defaultSortDirection และ sortRow(a, b, context) ส่วน manualSorting คง rows ตามลำดับที่ส่งมาและแสดงแค่สถานะการเรียง
ขนาดและแถบสลับสี
size กำหนดความสูงของแถว: xs 24px, sm 32px, md 40px, lg 48px (ค่าเริ่มต้น), xl 64px use-zebra-styles ใส่สีสลับทีละแถว use-static-width ทำให้ตารางกว้างเท่าเนื้อหาแทนที่จะเต็มกล่องที่ครอบ
xs
sm
md
lg
xl
แถบสลับสี
ผู้ลงนาม
ชื่อ
บทบาท
ลงนาม
อนันต์ พ. กรรมการผู้จัดการ 2026-10-01
กัญญา ศ. ที่ปรึกษากฎหมาย 2026-10-02
สมชาย ด. พยาน —
มาลี ก. พยาน 2026-10-03
HTML React React + Tailwind <div style ="display: flex; flex-wrap: wrap; gap: 16px; align-items: center" >
<ui-select id ="table-size-pick" inline label ="ขนาดแถว" value ="lg" >
<option value ="xs" >xs</option >
<option value ="sm" >sm</option >
<option value ="md" >md</option >
<option value ="lg" >lg</option >
<option value ="xl" >xl</option >
</ui-select >
<ui-checkbox id ="table-zebra-pick" >แถบสลับสี</ui-checkbox >
</div >
<ui-table id ="table-size" >
<ui-table-header-title slot ="title" >ผู้ลงนาม</ui-table-header-title >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >ชื่อ</ui-table-header-cell >
<ui-table-header-cell >บทบาท</ui-table-header-cell >
<ui-table-header-cell >ลงนาม</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row ><ui-table-cell >อนันต์ พ.</ui-table-cell ><ui-table-cell >กรรมการผู้จัดการ</ui-table-cell ><ui-table-cell >2026-10-01</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >กัญญา ศ.</ui-table-cell ><ui-table-cell >ที่ปรึกษากฎหมาย</ui-table-cell ><ui-table-cell >2026-10-02</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >สมชาย ด.</ui-table-cell ><ui-table-cell >พยาน</ui-table-cell ><ui-table-cell >—</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >มาลี ก.</ui-table-cell ><ui-table-cell >พยาน</ui-table-cell ><ui-table-cell >2026-10-03</ui-table-cell ></ui-table-row >
</ui-table-body >
</ui-table >
<script type ="module" >
const table = document.getElementById ('table-size' );
const size = document.getElementById ('table-size-pick' );
const zebra = document.getElementById ('table-zebra-pick' );
size.addEventListener ('change' , () => (table.size = size.value));
zebra.addEventListener ('change' , () => (table.useZebraStyles = zebra.checked));
</script >
<UiTable size = "sm" useZebraStyles >
<UiTableHeaderTitle slot = "title" >ผู้ลงนาม</UiTableHeaderTitle >
<UiTableHead >
<UiTableHeaderRow >{headerCells}</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => <UiTableRow key = {row.id}>{cells (row)}</UiTableRow >)}
</UiTableBody >
</UiTable >
<DataTable heading = "ผู้ลงนาม" size = "sm" zebra headers = {headers} rows = {rows} />
toolbar สูงตามขนาดของตาราง (24px สำหรับ xs, 32px สำหรับ sm, นอกนั้น 48px) และปรับขนาดปุ่มในแถบ batch ให้เข้ากัน ใน React + Tailwind ให้ใช้ปุ่ม size="sm" ใน toolbar และแถบ batch ของตาราง xs และ sm
การเลือกและ batch action
is-selectable ใส่ checkbox ให้ทุกแถว และช่องเลือกทั้งหมดในแถวหัวตาราง แถวที่มี disabled เลือกไม่ได้ ส่วน selected บนแถวคือเลือกแถวนั้น <ui-table-batch-actions> ใน toolbar ใส่ปุ่มของคุณ: ขณะมีแถวถูกเลือก มันจะทับ toolbar พร้อมจำนวนที่เลือกและปุ่ม Cancel ตารางยิง ui-table-row-selected พร้อม { selectedRow, selectedRows } และหลังเลือกทั้งหมดหรือ Cancel จะยิง ui-table-row-all-selected พร้อม { selectedRows } ส่วน selectedRows ของตารางเก็บแถวที่เลือกไว้ React + Tailwind รับ batchActions, selectedIds และ onSelectionChange
สัญญา
เลือกแถวเพื่อจัดการ
ดาวน์โหลด
เก็บเข้าคลัง
สัญญา
คู่สัญญา
สถานะ
สัญญาบริการ บริษัท เอซีเอ็ม จำกัด ลงนามแล้ว
สัญญารักษาความลับ โกลเบ็กซ์ ฉบับร่าง
ต่อสัญญาเช่า อินิเทค กำลังตรวจ
มติคณะกรรมการ แวนเดอเลย์ เก็บเข้าคลัง
ที่เลือก: 2
HTML React React + Tailwind <ui-table id ="table-select" is-selectable >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-header-description slot ="description" >เลือกแถวเพื่อจัดการ</ui-table-header-description >
<ui-table-toolbar slot ="toolbar" >
<ui-table-batch-actions >
<ui-button >ดาวน์โหลด</ui-button >
<ui-button >เก็บเข้าคลัง</ui-button >
</ui-table-batch-actions >
<ui-table-toolbar-content >
<ui-table-toolbar-search ></ui-table-toolbar-search >
</ui-table-toolbar-content >
</ui-table-toolbar >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >สัญญา</ui-table-header-cell >
<ui-table-header-cell >คู่สัญญา</ui-table-header-cell >
<ui-table-header-cell >สถานะ</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row data-id ="1" ><ui-table-cell >สัญญาบริการ</ui-table-cell ><ui-table-cell >บริษัท เอซีเอ็ม จำกัด</ui-table-cell ><ui-table-cell >ลงนามแล้ว</ui-table-cell ></ui-table-row >
<ui-table-row data-id ="2" selected ><ui-table-cell >สัญญารักษาความลับ</ui-table-cell ><ui-table-cell >โกลเบ็กซ์</ui-table-cell ><ui-table-cell >ฉบับร่าง</ui-table-cell ></ui-table-row >
<ui-table-row data-id ="3" ><ui-table-cell >ต่อสัญญาเช่า</ui-table-cell ><ui-table-cell >อินิเทค</ui-table-cell ><ui-table-cell >กำลังตรวจ</ui-table-cell ></ui-table-row >
<ui-table-row data-id ="4" disabled ><ui-table-cell >มติคณะกรรมการ</ui-table-cell ><ui-table-cell >แวนเดอเลย์</ui-table-cell ><ui-table-cell >เก็บเข้าคลัง</ui-table-cell ></ui-table-row >
</ui-table-body >
</ui-table >
<p >ที่เลือก: <output id ="table-select-out" >2</output ></p >
<script type ="module" >
const table = document.getElementById ('table-select' );
const show = () => {
document.getElementById ('table-select-out' ).value = table.selectedRows.map ((row) => row.dataset.id).join (', ' );
};
table.addEventListener ('ui-table-row-selected' , show);
table.addEventListener ('ui-table-row-all-selected' , show);
</script >
const [selected, setSelected] = useState (['2' ]);
const onSelect = (e: CustomEvent <{ selectedRows: HTMLElement [] }>) => setSelected (e.detail.selectedRows.map ((row) => row.dataset.id! ));
<UiTable isSelectable onUiTableRowSelected = {onSelect} onUiTableRowAllSelected = {onSelect}>
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableHeaderDescription slot = "description" >เลือกแถวเพื่อจัดการ</UiTableHeaderDescription >
<UiTableToolbar slot = "toolbar" >
<UiTableBatchActions >
<UiButton >ดาวน์โหลด</UiButton >
<UiButton onClick = {() => archive (selected)}>เก็บเข้าคลัง</UiButton >
</UiTableBatchActions >
<UiTableToolbarContent >
<UiTableToolbarSearch />
</UiTableToolbarContent >
</UiTableToolbar >
<UiTableHead >
<UiTableHeaderRow >{headerCells}</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => (
<UiTableRow key = {row.id} data-id = {row.id} selected = {selected.includes (row.id)} disabled = {row.disabled}>
{cells (row)}
</UiTableRow >
))}
</UiTableBody >
</UiTable >
const [selected, setSelected] = useState (['2' ]);
<DataTable
heading = "สัญญา"
description = "เลือกแถวเพื่อจัดการ"
selectable
headers = {headers}
rows = {rows}
selectedIds = {selected}
onSelectionChange = {(ids) => setSelected (ids)}
batchActions = {
<>
<Button >ดาวน์โหลด</Button >
<Button onClick = {() => archive (selected)}>เก็บเข้าคลัง</Button >
</>
}
/>
ช่องเลือกทั้งหมดทำตาม Carbon: ถ้ามีแถวที่เลือกอยู่ กดแล้วจะยกเลิกทั้งหมด ถ้าไม่มี จะเลือกทุกแถวที่เลือกได้ซึ่งการค้นหาแสดงอยู่ ก่อนแถวเปลี่ยน แถวจะยิง ui-table-row-change-selection ที่ยกเลิกได้ (แถวหัวตารางยิง ui-table-change-selection-all) ถ้าจะแต่ง style เอง แถวที่เลือกมี selected และแถวหัวตารางก็มี selected ขณะมีแถวใดถูกเลือก
เลือกหนึ่งแถว
radio ทำให้เลือกได้ทีละแถวด้วย radio บนทุกแถว เช่น ใช้เลือกแม่แบบ Tab จะหยุดที่แถวที่เลือก และปุ่มลูกศรย้ายพร้อมเลือก ไม่มีแถบ batch
เลือกแม่แบบ
แม่แบบ
ประเภท
แก้ไขล่าสุด
NDA มาตรฐาน รักษาความลับ 2026-06-01
สัญญาเช่าสำนักงาน อสังหาริมทรัพย์ 2026-03-15
สัญญาบริการหลัก บริการ 2025-11-20
แม่แบบ:
HTML React React + Tailwind <ui-table id ="table-radio" radio >
<ui-table-header-title slot ="title" >เลือกแม่แบบ</ui-table-header-title >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >แม่แบบ</ui-table-header-cell >
<ui-table-header-cell >ประเภท</ui-table-header-cell >
<ui-table-header-cell >แก้ไขล่าสุด</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row ><ui-table-cell >NDA มาตรฐาน</ui-table-cell ><ui-table-cell >รักษาความลับ</ui-table-cell ><ui-table-cell >2026-06-01</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >สัญญาเช่าสำนักงาน</ui-table-cell ><ui-table-cell >อสังหาริมทรัพย์</ui-table-cell ><ui-table-cell >2026-03-15</ui-table-cell ></ui-table-row >
<ui-table-row disabled ><ui-table-cell >สัญญาบริการหลัก</ui-table-cell ><ui-table-cell >บริการ</ui-table-cell ><ui-table-cell >2025-11-20</ui-table-cell ></ui-table-row >
</ui-table-body >
</ui-table >
<p >แม่แบบ: <output id ="table-radio-out" ></output ></p >
<script type ="module" >
const table = document.getElementById ('table-radio' );
table.addEventListener ('ui-table-row-selected' , (event) => {
document.getElementById ('table-radio-out' ).value = event.detail.selectedRow.querySelector ('ui-table-cell' ).textContent;
});
</script >
<UiTable radio onUiTableRowSelected = {(e) => setTemplate (e.detail.selectedRow.dataset.id)}>
<UiTableHeaderTitle slot = "title" >เลือกแม่แบบ</UiTableHeaderTitle >
<UiTableHead >
<UiTableHeaderRow >{headerCells}</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => <UiTableRow key = {row.id} data-id = {row.id} disabled = {row.disabled}>{cells (row)}</UiTableRow >)}
</UiTableBody >
</UiTable >
<DataTable heading = "เลือกแม่แบบ" radio headers = {headers} rows = {rows} onSelectionChange = {(ids) => setTemplate (ids[0 ])} />
ใส่ <ui-table-toolbar slot="toolbar"> ให้ตาราง แล้วใส่ <ui-table-toolbar-content> สำหรับตัวควบคุมไว้ในนั้น: <ui-table-toolbar-search>, overflow menu, ปุ่มหลัก ช่องค้นหาจะเป็นแค่แว่นขยายจนกว่าจะกด (expandable search ของ Carbon) persistent ให้เปิดค้างไว้ การพิมพ์จะซ่อนแถวที่เซลล์ที่แสดงอยู่ (และแถวที่ขยาย) ไม่มีข้อความนั้น แล้วตารางยิง ui-table-filtered พร้อม { unfilteredRows } ใน React + Tailwind searchable ใส่ช่องค้นหา และ prop toolbar รับตัวควบคุมอื่น
สัญญา
เก็บเข้าคลัง
เพิ่มสัญญา
สัญญา
คู่สัญญา
สถานะ
สัญญาบริการ บริษัท เอซีเอ็ม จำกัด ลงนามแล้ว
สัญญารักษาความลับ โกลเบ็กซ์ ฉบับร่าง
ต่อสัญญาเช่า อินิเทค กำลังตรวจ
สัญญาบริการหลัก อัมเบรลลา ลงนามแล้ว
แถวที่แสดง: 4
HTML React React + Tailwind <ui-table id ="table-toolbar" is-selectable >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-toolbar slot ="toolbar" >
<ui-table-batch-actions >
<ui-button >เก็บเข้าคลัง</ui-button >
</ui-table-batch-actions >
<ui-table-toolbar-content >
<ui-table-toolbar-search ></ui-table-toolbar-search >
<ui-overflow-menu size ="lg" label ="ตั้งค่า" placement ="bottom-end" tooltip-placement ="top" >
<svg slot ="icon" viewBox ="0 0 32 32" aria-hidden ="true" ><path d ="M27 16.76V15.24l1.92-1.68A2 2 0 0 0 29.3 11l-2.36-4a2 2 0 0 0-1.73-1 2 2 0 0 0-.64.1l-2.43.82a11.35 11.35 0 0 0-1.31-.75l-.51-2.52a2 2 0 0 0-2-1.61h-4.68a2 2 0 0 0-2 1.61l-.51 2.52a11.48 11.48 0 0 0-1.32.75l-2.38-.86A2 2 0 0 0 6.79 6a2 2 0 0 0-1.73 1L2.7 11a2 2 0 0 0 .41 2.51L5 15.24v1.52l-1.89 1.68A2 2 0 0 0 2.7 21l2.36 4a2 2 0 0 0 1.73 1 2 2 0 0 0 .64-.1l2.43-.82a11.35 11.35 0 0 0 1.31.75l.51 2.52a2 2 0 0 0 2 1.61h4.72a2 2 0 0 0 2-1.61l.51-2.52a11.48 11.48 0 0 0 1.32-.75l2.42.82a2 2 0 0 0 .64.1 2 2 0 0 0 1.73-1l2.28-4a2 2 0 0 0-.41-2.51ZM16 22a6 6 0 1 1 6-6 5.94 5.94 0 0 1-6 6Z" /></svg >
<ui-menu-item label ="แถวแบบกระชับ" ></ui-menu-item >
<ui-menu-item label ="แสดงที่เก็บเข้าคลัง" ></ui-menu-item >
</ui-overflow-menu >
<ui-button >เพิ่มสัญญา</ui-button >
</ui-table-toolbar-content >
</ui-table-toolbar >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >สัญญา</ui-table-header-cell >
<ui-table-header-cell >คู่สัญญา</ui-table-header-cell >
<ui-table-header-cell >สถานะ</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row ><ui-table-cell >สัญญาบริการ</ui-table-cell ><ui-table-cell >บริษัท เอซีเอ็ม จำกัด</ui-table-cell ><ui-table-cell >ลงนามแล้ว</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >สัญญารักษาความลับ</ui-table-cell ><ui-table-cell >โกลเบ็กซ์</ui-table-cell ><ui-table-cell >ฉบับร่าง</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >ต่อสัญญาเช่า</ui-table-cell ><ui-table-cell >อินิเทค</ui-table-cell ><ui-table-cell >กำลังตรวจ</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >สัญญาบริการหลัก</ui-table-cell ><ui-table-cell >อัมเบรลลา</ui-table-cell ><ui-table-cell >ลงนามแล้ว</ui-table-cell ></ui-table-row >
</ui-table-body >
</ui-table >
<p >แถวที่แสดง: <output id ="table-toolbar-out" >4</output ></p >
<script type ="module" >
const table = document.getElementById ('table-toolbar' );
table.addEventListener ('ui-table-filtered' , (event) => {
document.getElementById ('table-toolbar-out' ).value = event.detail.unfilteredRows.length;
});
</script >
<UiTable isSelectable onUiTableFiltered = {(e) => setShown (e.detail.unfilteredRows.length)}>
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableToolbar slot = "toolbar" >
<UiTableBatchActions >
<UiButton >เก็บเข้าคลัง</UiButton >
</UiTableBatchActions >
<UiTableToolbarContent >
<UiTableToolbarSearch />
<UiOverflowMenu size = "lg" label = "ตั้งค่า" placement = "bottom-end" tooltipPlacement = "top" >
<svg slot = "icon" viewBox = "0 0 32 32" aria-hidden = "true" >{settingsPath}</svg >
<UiMenuItem label = "แถวแบบกระชับ" />
<UiMenuItem label = "แสดงที่เก็บเข้าคลัง" />
</UiOverflowMenu >
<UiButton >เพิ่มสัญญา</UiButton >
</UiTableToolbarContent >
</UiTableToolbar >
<UiTableHead >
<UiTableHeaderRow >{headerCells}</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => <UiTableRow key = {row.id}>{cells (row)}</UiTableRow >)}
</UiTableBody >
</UiTable >
<DataTable
heading = "สัญญา"
searchable
selectable
headers = {headers}
rows = {rows}
onFilterChange = {setSearch}
toolbar = {
<>
<OverflowMenu size = "lg" label = "ตั้งค่า" placement = "bottom-end" tooltipPlacement = "top" icon = {<svg viewBox = "0 0 32 32" aria-hidden = "true" >{settingsPath}</svg >}>
<MenuItem label = "แถวแบบกระชับ" />
<MenuItem label = "แสดงที่เก็บเข้าคลัง" />
</OverflowMenu >
<Button >เพิ่มสัญญา</Button >
</>
}
batchActions = {<Button >เก็บเข้าคลัง</Button >}
/>
filterRows(rowText, searchString) บนตารางใช้เปลี่ยนเงื่อนไขการค้นหา: คืน true เพื่อซ่อนแถว (แบบ Carbon) ถ้าจะค้นหาที่ server ให้ตั้ง filterRows เป็น () => false แล้วฟัง input ของช่องค้นหา ซึ่ง value คือคำค้น label และ placeholder ของช่องค้นหาใช้แทนคำว่า "กรองตาราง" React + Tailwind มี filterRows(row, text, headers) ของตัวเอง (คืน true คือเก็บแถวไว้) filterText, manualFiltering และบอก screen reader ว่า "แสดง 3 จาก 12 แถว" เมื่อหยุดพิมพ์
แถวที่ขยายได้
expandable บนตาราง: แถวที่ตามด้วย <ui-table-expanded-row> จะมีลูกศรที่เปิดแถวรายละเอียดเต็มความกว้างนั้นใต้แถว batch-expansion ใส่ลูกศรในแถวหัวตารางที่เปิดหรือปิดทุกแถว และ expanded บนแถวคือเปิดแถวนั้น แถวยิง ui-table-row-expando-beingtoggled ที่ยกเลิกได้ แล้วยิง ui-table-row-expando-toggled พร้อม { expanded }
สัญญา
สัญญา
คู่สัญญา
สถานะ
สัญญาบริการ บริษัท เอซีเอ็ม จำกัด ลงนามแล้ว
ผู้รับผิดชอบ: กัญญา ศ. · สิ้นสุด 2027-09-30
สัญญารักษาความลับ โกลเบ็กซ์ ฉบับร่าง
ผู้รับผิดชอบ: อนันต์ พ. · สิ้นสุด 2028-10-01
ต่อสัญญาเช่า อินิเทค กำลังตรวจ
ผู้รับผิดชอบ: มาลี ก. · สิ้นสุด 2029-01-31
HTML React React + Tailwind <ui-table expandable batch-expansion >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >สัญญา</ui-table-header-cell >
<ui-table-header-cell >คู่สัญญา</ui-table-header-cell >
<ui-table-header-cell >สถานะ</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row ><ui-table-cell >สัญญาบริการ</ui-table-cell ><ui-table-cell >บริษัท เอซีเอ็ม จำกัด</ui-table-cell ><ui-table-cell >ลงนามแล้ว</ui-table-cell ></ui-table-row >
<ui-table-expanded-row >ผู้รับผิดชอบ: กัญญา ศ. · สิ้นสุด 2027-09-30</ui-table-expanded-row >
<ui-table-row expanded ><ui-table-cell >สัญญารักษาความลับ</ui-table-cell ><ui-table-cell >โกลเบ็กซ์</ui-table-cell ><ui-table-cell >ฉบับร่าง</ui-table-cell ></ui-table-row >
<ui-table-expanded-row >ผู้รับผิดชอบ: อนันต์ พ. · สิ้นสุด 2028-10-01</ui-table-expanded-row >
<ui-table-row ><ui-table-cell >ต่อสัญญาเช่า</ui-table-cell ><ui-table-cell >อินิเทค</ui-table-cell ><ui-table-cell >กำลังตรวจ</ui-table-cell ></ui-table-row >
<ui-table-expanded-row >ผู้รับผิดชอบ: มาลี ก. · สิ้นสุด 2029-01-31</ui-table-expanded-row >
</ui-table-body >
</ui-table >
<UiTable expandable batchExpansion >
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableHead >
<UiTableHeaderRow >{headerCells}</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => (
<Fragment key = {row.id}>
<UiTableRow expanded = {row.id === '2' }>{cells (row)}</UiTableRow >
<UiTableExpandedRow >ผู้รับผิดชอบ: {row.owner} · สิ้นสุด {row.ends}</UiTableExpandedRow >
</Fragment >
))}
</UiTableBody >
</UiTable >
<DataTable
heading = "สัญญา"
expandAll
headers = {headers}
rows = {rows}
defaultExpandedIds = {['2' ]}
renderExpandedRow = {(row) => <p className = "m-0" >ผู้รับผิดชอบ: {String (row.owner)} · สิ้นสุด {String (row.ends)}</p >}
/>
แบ่งหน้า
page-size ใส่แถบแบ่งหน้า ใต้ตาราง ซึ่งแสดงแถวเท่าจำนวนนั้นจากแถวที่ผ่านการเรียงและการค้นหา page และ page-sizes กำหนดหน้าและตัวเลือกจำนวนต่อหน้า และ ui-table-page-change ยิงพร้อม { page, pageSize } ช่องเลือกทั้งหมดจะเลือกเฉพาะหน้านั้น และแถบ batch มี "เลือกทั้งหมด (N)" สำหรับทุกแถวที่การค้นหาแสดง Carbon ไม่มีการแบ่งหน้าในตัวตาราง แต่วาง Pagination ไว้ข้างใต้
สัญญา
ลบ
สัญญา
คู่สัญญา
สถานะ
HTML React React + Tailwind <ui-table id ="table-pages" is-selectable page-size ="5" page-sizes ="5,10,20" >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-toolbar slot ="toolbar" >
<ui-table-batch-actions >
<ui-button >ลบ</ui-button >
</ui-table-batch-actions >
<ui-table-toolbar-content >
<ui-table-toolbar-search ></ui-table-toolbar-search >
</ui-table-toolbar-content >
</ui-table-toolbar >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >สัญญา</ui-table-header-cell >
<ui-table-header-cell >คู่สัญญา</ui-table-header-cell >
<ui-table-header-cell >สถานะ</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body ></ui-table-body >
</ui-table >
<script type ="module" >
const statuses = ['ฉบับร่าง' , 'กำลังตรวจ' , 'ลงนามแล้ว' , 'เก็บเข้าคลัง' ];
const parties = ['เอซีเอ็ม' , 'โกลเบ็กซ์' , 'อินิเทค' , 'อัมเบรลลา' ];
const cell = (text) => `<ui-table-cell>${ text }</ui-table-cell>` ;
const row = (i) => `<ui-table-row>${ cell ( `สัญญาเลขที่ ${ String (i + 1 ). padStart ( 3 , '0' ) }` ) }${ cell (parties[i % 4 ]) }${ cell (statuses[i % 4 ]) }</ui-table-row>` ;
document.querySelector ('#table-pages ui-table-body' ).innerHTML = Array.from ({ length: 23 }, (_, i) => row (i)).join ('' );
</script >
<UiTable isSelectable pageSize = {5 } pageSizes = "5,10,20" onUiTablePageChange = {(e) => console.log (e.detail)}>
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableToolbar slot = "toolbar" >
<UiTableBatchActions >
<UiButton >ลบ</UiButton >
</UiTableBatchActions >
<UiTableToolbarContent >
<UiTableToolbarSearch />
</UiTableToolbarContent >
</UiTableToolbar >
<UiTableHead >
<UiTableHeaderRow >{headerCells}</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => <UiTableRow key = {row.id}>{cells (row)}</UiTableRow >)}
</UiTableBody >
</UiTable >
<DataTable heading = "สัญญา" sortable searchable selectable defaultPageSize = {10 } headers = {headers} rows = {rows} onPageChange = {(change) => console.log (change)} batchActions = {<Button >ลบ</Button >} />
ถ้าแบ่งหน้าที่ server ให้ render แถวทีละหน้า วาง <ui-pagination> ของคุณเองใต้ตาราง แล้วเรียงและค้นหาที่ server (ยกเลิก ui-table-header-cell-sort, ใช้ filterRows ที่เก็บทุกแถว และฟัง input ของช่องค้นหา) บน <ui-table-batch-actions> total-rows-count ทำให้มี "เลือกทั้งหมด (N)" สำหรับแถวที่ไม่ได้อยู่ในตาราง (ยิง ui-table-batch-actions-select-all-clicked แล้วคุณเลือกเอง) และการตั้ง selected-rows-count ใน listener ของ ui-table-row-selected ใช้นับการเลือกที่ข้ามหน้า React + Tailwind ทำแบบเดียวกันด้วย manualSorting, manualFiltering, totalSelected, totalCount และ onSelectAll
แสดงและซ่อนคอลัมน์
<ui-table-column-settings> ใน toolbar content ใส่ปุ่ม Columns ที่มีรายการ checkbox ของคอลัมน์ หัวคอลัมน์ที่มี hideable="false" แสดงเสมอ และหัวคอลัมน์ที่มี column-hidden เริ่มต้นแบบซ่อน ปุ่ม Reset กลับไปเป็นคอลัมน์ที่ซ่อนตาม markup column ตั้งชื่อคอลัมน์ (ค่าเริ่มต้นคือลำดับ "0", "1" …) ตารางยิง ui-table-columns-change พร้อม { hiddenColumns, column, hidden } เก็บ hiddenColumns ไว้แล้วคืนค่าด้วย column-hidden บนหัวคอลัมน์ หรือ setColumnHidden(column, hidden) ของตาราง คอลัมน์ที่ซ่อนจะไม่ถูกค้นหาและไม่อยู่ในไฟล์ CSV ด้วย
สัญญา
สัญญา
คู่สัญญา
สถานะ
แก้ไขล่าสุด
สัญญาบริการ บริษัท เอซีเอ็ม จำกัด ลงนามแล้ว 2026-09-30
สัญญารักษาความลับ โกลเบ็กซ์ ฉบับร่าง 2026-10-01
ต่อสัญญาเช่า อินิเทค กำลังตรวจ 2026-09-12
ที่ซ่อน: updated
HTML React React + Tailwind <ui-table id ="table-columns" >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-toolbar slot ="toolbar" >
<ui-table-toolbar-content >
<ui-table-toolbar-search ></ui-table-toolbar-search >
<ui-table-column-settings ></ui-table-column-settings >
</ui-table-toolbar-content >
</ui-table-toolbar >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell column ="name" hideable ="false" >สัญญา</ui-table-header-cell >
<ui-table-header-cell column ="party" >คู่สัญญา</ui-table-header-cell >
<ui-table-header-cell column ="status" >สถานะ</ui-table-header-cell >
<ui-table-header-cell column ="updated" column-hidden >แก้ไขล่าสุด</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row ><ui-table-cell >สัญญาบริการ</ui-table-cell ><ui-table-cell >บริษัท เอซีเอ็ม จำกัด</ui-table-cell ><ui-table-cell >ลงนามแล้ว</ui-table-cell ><ui-table-cell >2026-09-30</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >สัญญารักษาความลับ</ui-table-cell ><ui-table-cell >โกลเบ็กซ์</ui-table-cell ><ui-table-cell >ฉบับร่าง</ui-table-cell ><ui-table-cell >2026-10-01</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >ต่อสัญญาเช่า</ui-table-cell ><ui-table-cell >อินิเทค</ui-table-cell ><ui-table-cell >กำลังตรวจ</ui-table-cell ><ui-table-cell >2026-09-12</ui-table-cell ></ui-table-row >
</ui-table-body >
</ui-table >
<p >ที่ซ่อน: <output id ="table-columns-out" >updated</output ></p >
<script type ="module" >
const table = document.getElementById ('table-columns' );
table.addEventListener ('ui-table-columns-change' , (event) => {
document.getElementById ('table-columns-out' ).value = event.detail.hiddenColumns.join (', ' );
});
</script >
const saved = loadHiddenColumns (); // เช่น ['updated'] จาก storage
<UiTable onUiTableColumnsChange = {(e) => saveHiddenColumns (e.detail.hiddenColumns)}>
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableToolbar slot = "toolbar" >
<UiTableToolbarContent >
<UiTableToolbarSearch />
<UiTableColumnSettings />
</UiTableToolbarContent >
</UiTableToolbar >
<UiTableHead >
<UiTableHeaderRow >
{headers.map ((h) => (
<UiTableHeaderCell key = {h.key} column = {h.key} hideable = {h.key !== 'name' } columnHidden = {saved.includes (h.key)}>
{h.header}
</UiTableHeaderCell >
))}
</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => <UiTableRow key = {row.id}>{cells (row)}</UiTableRow >)}
</UiTableBody >
</UiTable >
<DataTable heading = "สัญญา" searchable columnSettings headers = {headers} rows = {rows} hiddenColumns = {hidden} onColumnsChange = {(change) => setHidden (change.hiddenColumns)} />
หัวตารางติดบนและคอลัมน์ที่ตรึงไว้
sticky-header ให้แถวหัวตารางอยู่ในจอขณะเลื่อนตัวตารางในกล่องที่สูงไม่เกิน --ui-table-max-height (300px ตาม Carbon) สำหรับตารางกว้าง pinned="start" บนหัวคอลัมน์แรกตรึงคอลัมน์นั้น (และคอลัมน์ลูกศรกับ checkbox ที่อยู่ก่อนหน้า) ไว้ขณะที่ส่วนที่เหลือเลื่อนด้านข้าง และ pinned="end" บนหัวคอลัมน์สุดท้ายตรึงปุ่มของแถวไว้ด้านท้าย การตรึงเริ่มทำงานเมื่อหน้าต่างกว้างตั้งแต่ 672px
สัญญา
20 แถว: เลื่อนลง แล้วเลื่อนด้านข้าง
สัญญา
คู่สัญญา
ผู้รับผิดชอบ
ฝ่าย
แก้ไขล่าสุด
การทำงาน
HTML React React + Tailwind <div style ="max-inline-size: 560px" >
<ui-table id ="table-scroll" sticky-header is-selectable >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-header-description slot ="description" >20 แถว: เลื่อนลง แล้วเลื่อนด้านข้าง</ui-table-header-description >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell pinned ="start" >สัญญา</ui-table-header-cell >
<ui-table-header-cell >คู่สัญญา</ui-table-header-cell >
<ui-table-header-cell >ผู้รับผิดชอบ</ui-table-header-cell >
<ui-table-header-cell >ฝ่าย</ui-table-header-cell >
<ui-table-header-cell >แก้ไขล่าสุด</ui-table-header-cell >
<ui-table-header-cell pinned ="end" >การทำงาน</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body ></ui-table-body >
</ui-table >
</div >
<script type ="module" >
const parties = ['บริษัท เอซีเอ็ม จำกัด' , 'โกลเบ็กซ์' , 'อินิเทค' , 'อัมเบรลลา' ];
const cell = (text) => `<ui-table-cell>${ text }</ui-table-cell>` ;
const updated = (i) => `2026-09-${ String ((i % 28 ) + 1 ). padStart ( 2 , '0' ) }` ;
const row = (i) => `<ui-table-row>${ [ `สัญญาเลขที่ ${ i + 1 }` , parties[i % 4 ], 'สมชาย ใจดี' , 'ฝ่ายกฎหมาย' , updated (i), 'เปิด' ]. map (cell). join ( '' ) }</ui-table-row>` ;
document.querySelector ('#table-scroll ui-table-body' ).innerHTML = Array.from ({ length: 20 }, (_, i) => row (i)).join ('' );
</script >
<UiTable stickyHeader isSelectable >
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableHead >
<UiTableHeaderRow >
<UiTableHeaderCell pinned = "start" >สัญญา</UiTableHeaderCell >
…
<UiTableHeaderCell pinned = "end" >การทำงาน</UiTableHeaderCell >
</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => <UiTableRow key = {row.id}>{cells (row)}</UiTableRow >)}
</UiTableBody >
</UiTable >
<DataTable heading = "สัญญา" stickyHeader selectable headers = {[{ key: 'name' , header: 'สัญญา' , pinned: 'start' }, …, { key: 'action' , header: 'การทำงาน' , pinned: 'end' }]} rows = {rows} />
เปลี่ยนความสูงของกล่องด้วย CSS: ui-table { --ui-table-max-height: 480px; } ส่วน DataTable ของ React + Tailwind อ่าน --ui-data-table-max-height
ส่งออก CSV
<ui-table-csv-export> ใน toolbar content ใส่ปุ่ม Export CSV: ดาวน์โหลดคอลัมน์ที่แสดงและแถวที่การค้นหาแสดง (ตามลำดับที่เรียง ทุกหน้า) เป็นไฟล์ CSV สำหรับ Excel ตั้งชื่อตาม file-name ของมัน หรือชื่อตาราง ก่อนดาวน์โหลดจะยิง ui-table-csv-export ที่ยกเลิกได้พร้อม { csv, rows, fileName } เซลล์เขียน csv-value ถ้ามี ถ้าไม่มีใช้ข้อความ toCsv({ scope }) และ downloadCsv({ scope, fileName }) ของตารางส่งออกแถว 'shown', 'selected' หรือ 'all' จากปุ่มของคุณเอง ตัวอย่างนี้แสดง CSV แทนการดาวน์โหลด
สัญญา
ส่งออกที่เลือก
สัญญา
คู่สัญญา
จำนวนเงิน (บาท)
สัญญาบริการ บริษัท เอซีเอ็ม จำกัด 1,250,000
สัญญารักษาความลับ โกลเบ็กซ์ 0
ต่อสัญญาเช่า อินิเทค 480,000
HTML React React + Tailwind <ui-table id ="table-csv" is-selectable >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-toolbar slot ="toolbar" >
<ui-table-batch-actions >
<ui-button id ="table-csv-selected" >ส่งออกที่เลือก</ui-button >
</ui-table-batch-actions >
<ui-table-toolbar-content >
<ui-table-toolbar-search ></ui-table-toolbar-search >
<ui-table-csv-export ></ui-table-csv-export >
</ui-table-toolbar-content >
</ui-table-toolbar >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >สัญญา</ui-table-header-cell >
<ui-table-header-cell >คู่สัญญา</ui-table-header-cell >
<ui-table-header-cell >จำนวนเงิน (บาท)</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row ><ui-table-cell >สัญญาบริการ</ui-table-cell ><ui-table-cell >บริษัท เอซีเอ็ม จำกัด</ui-table-cell ><ui-table-cell csv-value ="1250000" >1,250,000</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >สัญญารักษาความลับ</ui-table-cell ><ui-table-cell >โกลเบ็กซ์</ui-table-cell ><ui-table-cell csv-value ="0" >0</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >ต่อสัญญาเช่า</ui-table-cell ><ui-table-cell >อินิเทค</ui-table-cell ><ui-table-cell csv-value ="480000" >480,000</ui-table-cell ></ui-table-row >
</ui-table-body >
</ui-table >
<pre id ="table-csv-out" style ="margin: 0; white-space: pre-wrap; font: var(--ui-font-code)" ></pre >
<script type ="module" >
const table = document.getElementById ('table-csv' );
const out = document.getElementById ('table-csv-out' );
table.addEventListener ('ui-table-csv-export' , (event) => {
event.preventDefault (); // ตัวอย่างนี้แสดงไฟล์แทนการดาวน์โหลด
out.textContent = event.detail.csv;
});
document.getElementById ('table-csv-selected' ).addEventListener ('click' , () => {
out.textContent = table.toCsv ({ scope: 'selected' }); // หรือ table.downloadCsv({ scope: 'selected' })
});
</script >
import type { UiTable as TableElement } from '@purpurabog/ui' ;
const table = useRef <TableElement >(null );
<UiTable ref = {table} isSelectable >
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableToolbar slot = "toolbar" >
<UiTableBatchActions >
<UiButton onClick = {() => table.current?.downloadCsv ({ scope: 'selected' , fileName: 'สัญญาที่เลือก' })}>ส่งออกที่เลือก</UiButton >
</UiTableBatchActions >
<UiTableToolbarContent >
<UiTableToolbarSearch />
<UiTableCsvExport />
</UiTableToolbarContent >
</UiTableToolbar >
<UiTableHead >
<UiTableHeaderRow >{headerCells}</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => <UiTableRow key = {row.id}>{cells (row)}</UiTableRow >)}
</UiTableBody >
</UiTable >
import { dataTableToCsv, downloadCsv } from '@/components/ui/react-tw/data-table-csv' ;
const [selected, setSelected] = useState <string []>([]);
<DataTable
heading = "สัญญา"
searchable
selectable
csvExport
headers = {headers}
rows = {rows}
selectedIds = {selected}
onSelectionChange = {setSelected}
batchActions = {
<Button onClick = {() => downloadCsv (dataTableToCsv (headers, rows.filter ((r) => selected.includes (r.id))), 'สัญญาที่เลือก' )}>ส่งออกที่เลือก</Button >
}
/>
ไฟล์เป็น UTF-8 ที่มี byte order mark เพื่อให้ Excel อ่านภาษาไทยถูก ทุกเซลล์อยู่ในเครื่องหมายคำพูด และเซลล์ที่ขึ้นต้นเหมือนสูตรจะถูกทำให้ปลอดภัย
แก้ไขเซลล์ในตาราง
ใส่ editable="text", "number" หรือ "select" (พร้อม options เป็นรายการ { value, label } ทาง property หรือ JSON ใน attribute) ให้หัวคอลัมน์ แล้วเซลล์ของคอลัมน์นั้นจะแก้ไขได้: ตารางกลายเป็น grid ที่หยุด Tab ที่เดียว และปุ่มลูกศรย้ายระหว่างเซลล์ Enter, F2, ดับเบิลคลิก หรือพิมพ์ จะเปิดช่องแก้ไข Enter บันทึก Escape ยกเลิก Tab บันทึกแล้วไปแก้เซลล์ถัดไปที่แก้ได้ validate(value, cell) ของหัวคอลัมน์คืนข้อความเพื่อให้ช่องแก้ไขเปิดค้างไว้ การบันทึกยิง ui-table-cell-edit ที่ยกเลิกได้จากเซลล์พร้อม { row, cell, column, value, previous } แล้วจึงเขียนค่าลงเซลล์
สัญญา
focus ที่เซลล์แล้วกด Enter หรือดับเบิลคลิก
ชื่อ
จำนวนเงิน (บาท)
สถานะ
ผู้รับผิดชอบ
สัญญาเช่าสำนักงาน 2569 250000 กำลังตรวจ อนัญญา
NDA – เอซีเอ็ม 0 ลงนามแล้ว บุญศรี
สัญญาอนุญาตใช้ซอฟต์แวร์ 48000 ฉบับร่าง ชัย
แก้ไขล่าสุด:
HTML React React + Tailwind <ui-table id ="table-edit" >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-header-description slot ="description" >focus ที่เซลล์แล้วกด Enter หรือดับเบิลคลิก</ui-table-header-description >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell column ="name" editable ="text" >ชื่อ</ui-table-header-cell >
<ui-table-header-cell column ="amount" editable ="number" >จำนวนเงิน (บาท)</ui-table-header-cell >
<ui-table-header-cell column ="status" editable ="select" options ='[{"value":"draft","label":"ฉบับร่าง"},{"value":"review","label":"กำลังตรวจ"},{"value":"signed","label":"ลงนามแล้ว"}]' >สถานะ</ui-table-header-cell >
<ui-table-header-cell column ="owner" >ผู้รับผิดชอบ</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row ><ui-table-cell >สัญญาเช่าสำนักงาน 2569</ui-table-cell ><ui-table-cell >250000</ui-table-cell ><ui-table-cell >กำลังตรวจ</ui-table-cell ><ui-table-cell >อนัญญา</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >NDA – เอซีเอ็ม</ui-table-cell ><ui-table-cell >0</ui-table-cell ><ui-table-cell >ลงนามแล้ว</ui-table-cell ><ui-table-cell >บุญศรี</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >สัญญาอนุญาตใช้ซอฟต์แวร์</ui-table-cell ><ui-table-cell >48000</ui-table-cell ><ui-table-cell >ฉบับร่าง</ui-table-cell ><ui-table-cell >ชัย</ui-table-cell ></ui-table-row >
</ui-table-body >
</ui-table >
<p >แก้ไขล่าสุด: <output id ="table-edit-out" ></output ></p >
<script type ="module" >
const table = document.getElementById ('table-edit' );
const [name, amount] = table.querySelectorAll ('ui-table-header-cell' );
name.validate = (value) => (String (value).trim () ? '' : 'ต้องใส่ชื่อ' );
amount.validate = (value) => (Number (value) >= 0 ? '' : 'ต้องเป็น 0 หรือมากกว่า' );
table.addEventListener ('ui-table-cell-edit' , (event) => {
const { column, previous, value } = event.detail;
document.getElementById ('table-edit-out' ).value = `${ column }: ${ previous } → ${ value }` ;
});
</script >
const statusOptions = [
{ value: 'draft' , label: 'ฉบับร่าง' },
{ value: 'review' , label: 'กำลังตรวจ' },
{ value: 'signed' , label: 'ลงนามแล้ว' },
];
const [rows, setRows] = useState (initialRows);
<UiTable
onUiTableCellEdit = {(e) => {
e.preventDefault (); // React render เซลล์เอง ให้แก้ข้อมูลแทน
const { row, column, value } = e.detail;
setRows ((all) => all.map ((r) => (r.id === row.dataset.id ? { ... r, [column]: value } : r)));
}}
>
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableHead >
<UiTableHeaderRow >
<UiTableHeaderCell column = "name" editable = "text" validate = {(value) => (String (value).trim () ? '' : 'ต้องใส่ชื่อ' )}>ชื่อ</UiTableHeaderCell >
<UiTableHeaderCell column = "amount" editable = "number" >จำนวนเงิน (บาท)</UiTableHeaderCell >
<UiTableHeaderCell column = "status" editable = "select" options = {statusOptions}>สถานะ</UiTableHeaderCell >
<UiTableHeaderCell column = "owner" >ผู้รับผิดชอบ</UiTableHeaderCell >
</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => (
<UiTableRow key = {row.id} data-id = {row.id}>
<UiTableCell >{row.name}</UiTableCell >
<UiTableCell >{row.amount}</UiTableCell >
<UiTableCell >{statusOptions.find ((o) => o.value === row.status)?.label}</UiTableCell >
<UiTableCell >{row.owner}</UiTableCell >
</UiTableRow >
))}
</UiTableBody >
</UiTable >
const [rows, setRows] = useState (initialRows);
<DataTable heading = "สัญญา" headers = {headers} rows = {rows} onCellEdit = {(edit) => setRows (edit.rows)} />
ถ้าไม่ยกเลิก ตารางจะเขียนค่าที่บันทึกลงเซลล์เอง (เป็นข้อความ หรือ label ของคอลัมน์ select) แถวที่ framework render เป็นของ framework นั้น จึงต้องเรียก preventDefault() ใน ui-table-cell-edit แล้วแก้ข้อมูลของคุณ แบบในแท็บ React ถ้าจะปฏิเสธการแก้ไข ให้ยกเลิก event แล้วคงข้อมูลเดิมไว้ ส่วน React + Tailwind ส่ง rows ชุดใหม่มาใน onCellEdit: ตั้งค่าตามนั้น หรือคง rows เดิมไว้เพื่อปฏิเสธการแก้ไข
ปรับความกว้างคอลัมน์
resizable บนตารางใส่ที่จับที่ขอบท้ายของหัวคอลัมน์ทุกตัว ส่วน resizable บนหัวคอลัมน์บางตัวใส่เฉพาะตัวนั้น: ลากที่จับ หรือกด Tab ไปที่มันแล้วใช้ปุ่มลูกศร (กด Shift เพื่อขยับทีละ 16px) width, min-width (ค่าเริ่มต้น 50) และ max-width เป็น px บนหัวคอลัมน์กำหนดขอบเขต ทุกครั้งที่ปรับเสร็จ หัวคอลัมน์ยิง ui-table-column-resize พร้อม { column, width } ส่วน columnWidths ของตารางเก็บความกว้างทุกคอลัมน์ เก็บค่าไว้แล้วตั้ง width บนหัวคอลัมน์เพื่อคืนค่า
สัญญา
ลากขอบท้ายของหัวคอลัมน์ คอลัมน์จำนวนเงินปรับไม่ได้
ชื่อ
สถานะ
ผู้รับผิดชอบ
จำนวนเงิน (บาท)
สัญญาเช่าสำนักงาน 2569 กำลังตรวจ อนัญญา 250,000
NDA – เอซีเอ็ม ลงนามแล้ว บุญศรี 0
สัญญาอนุญาตใช้ซอฟต์แวร์ ฉบับร่าง ชัย 48,000
ความกว้าง:
HTML React React + Tailwind <ui-table id ="table-resize" >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-header-description slot ="description" >ลากขอบท้ายของหัวคอลัมน์ คอลัมน์จำนวนเงินปรับไม่ได้</ui-table-header-description >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell column ="name" resizable min-width ="120" >ชื่อ</ui-table-header-cell >
<ui-table-header-cell column ="status" resizable >สถานะ</ui-table-header-cell >
<ui-table-header-cell column ="owner" resizable >ผู้รับผิดชอบ</ui-table-header-cell >
<ui-table-header-cell column ="amount" >จำนวนเงิน (บาท)</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row ><ui-table-cell >สัญญาเช่าสำนักงาน 2569</ui-table-cell ><ui-table-cell >กำลังตรวจ</ui-table-cell ><ui-table-cell >อนัญญา</ui-table-cell ><ui-table-cell >250,000</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >NDA – เอซีเอ็ม</ui-table-cell ><ui-table-cell >ลงนามแล้ว</ui-table-cell ><ui-table-cell >บุญศรี</ui-table-cell ><ui-table-cell >0</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >สัญญาอนุญาตใช้ซอฟต์แวร์</ui-table-cell ><ui-table-cell >ฉบับร่าง</ui-table-cell ><ui-table-cell >ชัย</ui-table-cell ><ui-table-cell >48,000</ui-table-cell ></ui-table-row >
</ui-table-body >
</ui-table >
<p >ความกว้าง: <output id ="table-resize-out" ></output ></p >
<script type ="module" >
const table = document.getElementById ('table-resize' );
table.addEventListener ('ui-table-column-resize' , () => {
document.getElementById ('table-resize-out' ).value = JSON.stringify (table.columnWidths);
});
</script >
const [widths, setWidths] = useState <Record <string , number >>({});
<UiTable onUiTableColumnResize = {(e) => setWidths ((all) => ({ ... all, [e.detail.column]: e.detail.width }))}>
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableHead >
<UiTableHeaderRow >
{headers.map ((h) => (
<UiTableHeaderCell key = {h.key} column = {h.key} resizable = {h.key !== 'amount' } width = {widths[h.key]}>
{h.header}
</UiTableHeaderCell >
))}
</UiTableHeaderRow >
</UiTableHead >
<UiTableBody >
{rows.map ((row) => <UiTableRow key = {row.id}>{cells (row)}</UiTableRow >)}
</UiTableBody >
</UiTable >
<DataTable heading = "สัญญา" resizable sortable headers = {headers} rows = {rows} columnWidths = {widths} onColumnResize = {(change) => setWidths (change.widths)} />
ว่าง กำลังโหลด และ skeleton
ถ้าไม่มีแถว ตารางจะบอกว่า "ไม่มีข้อมูล" ใต้หัวตาราง ใส่ข้อความของคุณเองใน slot empty (emptyText ใน React + Tailwind) ถ้าค้นหาแล้วไม่เจอจะบอกว่า "ไม่พบข้อมูลที่ค้นหา" (slot no-results, noResultsText) loading คง toolbar และหัวตารางไว้ แล้วแสดงแถว skeleton (loading-rows ค่าเริ่มต้นคือจำนวนแถวที่แสดงอยู่) ระหว่างโหลดข้อมูลใหม่ ก่อนข้อมูลชุดแรกมาถึง ให้แสดง <ui-table-skeleton> แทนตาราง
สัญญา
ชื่อ
บทบาท
ลงนาม
ยังไม่มีสัญญา สร้างสัญญาแรกเพื่อเริ่มต้น
โหลดใหม่
ผู้ลงนาม
ชื่อ
บทบาท
ลงนาม
อนันต์ พ. กรรมการผู้จัดการ 2026-10-01
กัญญา ศ. ที่ปรึกษากฎหมาย 2026-10-02
HTML React React + Tailwind <ui-table >
<ui-table-header-title slot ="title" >สัญญา</ui-table-header-title >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >ชื่อ</ui-table-header-cell >
<ui-table-header-cell >บทบาท</ui-table-header-cell >
<ui-table-header-cell >ลงนาม</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body ></ui-table-body >
<div slot ="empty" ><strong >ยังไม่มีสัญญา</strong ><br />สร้างสัญญาแรกเพื่อเริ่มต้น</div >
</ui-table >
<div ><ui-button id ="table-reload" kind ="tertiary" size ="sm" >โหลดใหม่</ui-button ></div >
<ui-table id ="table-loading" >
<ui-table-header-title slot ="title" >ผู้ลงนาม</ui-table-header-title >
<ui-table-toolbar slot ="toolbar" >
<ui-table-toolbar-content >
<ui-table-toolbar-search ></ui-table-toolbar-search >
</ui-table-toolbar-content >
</ui-table-toolbar >
<ui-table-head >
<ui-table-header-row >
<ui-table-header-cell >ชื่อ</ui-table-header-cell >
<ui-table-header-cell >บทบาท</ui-table-header-cell >
<ui-table-header-cell >ลงนาม</ui-table-header-cell >
</ui-table-header-row >
</ui-table-head >
<ui-table-body >
<ui-table-row ><ui-table-cell >อนันต์ พ.</ui-table-cell ><ui-table-cell >กรรมการผู้จัดการ</ui-table-cell ><ui-table-cell >2026-10-01</ui-table-cell ></ui-table-row >
<ui-table-row ><ui-table-cell >กัญญา ศ.</ui-table-cell ><ui-table-cell >ที่ปรึกษากฎหมาย</ui-table-cell ><ui-table-cell >2026-10-02</ui-table-cell ></ui-table-row >
</ui-table-body >
</ui-table >
<ui-table-skeleton column-count ="3" row-count ="3" ></ui-table-skeleton >
<script type ="module" >
const loading = document.getElementById ('table-loading' );
document.getElementById ('table-reload' ).addEventListener ('click' , () => {
loading.loading = true ;
setTimeout (() => (loading.loading = false ), 1500 );
});
</script >
<UiTable >
<UiTableHeaderTitle slot = "title" >สัญญา</UiTableHeaderTitle >
<UiTableHead >
<UiTableHeaderRow >{headerCells}</UiTableHeaderRow >
</UiTableHead >
<UiTableBody />
<div slot = "empty" ><strong >ยังไม่มีสัญญา</strong ><br />สร้างสัญญาแรกเพื่อเริ่มต้น</div >
</UiTable >
<UiTable loading = {reloading}>
<UiTableHeaderTitle slot = "title" >ผู้ลงนาม</UiTableHeaderTitle >
…
</UiTable >
<UiTableSkeleton columnCount = {3 } rowCount = {3 } />
import { DataTable, DataTableSkeleton } from '@/components/ui/react-tw/data-table' ;
<DataTable heading = "สัญญา" headers = {headers} rows = {[]} emptyText = {<><strong >ยังไม่มีสัญญา</strong ><br />สร้างสัญญาแรกเพื่อเริ่มต้น</>} />
<DataTable heading = "ผู้ลงนาม" searchable loading = {reloading} headers = {headers} rows = {rows} />
<DataTableSkeleton columnCount = {3 } rowCount = {3 } />
skeleton ซ่อนจาก screen reader ให้ใส่ aria-busy และข้อความสถานะที่ส่วนที่ครอบอยู่ รับ headers (property: ชื่อคอลัมน์) เพื่อแสดงชื่อคอลัมน์จริง zebra, show-header="false" และ show-toolbar="false" ส่วน DataTableSkeleton ของ React + Tailwind รับ headers, size, zebra, hideHeader และ hideToolbar
คีย์บอร์ด
ปุ่ม
ทำอะไร
Tab
ไปตาม toolbar ปุ่มเรียง checkbox และตัวควบคุมในเซลล์ ตาราง radio และ grid ที่แก้ไขได้หยุด Tab ที่เดียว
Space
ติ๊ก checkbox เลือกแถว radio ที่ focus อยู่
ขึ้น / ลง
ในตาราง radio ย้ายไปแถวก่อนหน้า / ถัดไปและเลือก
ลูกศร, Home / End, Ctrl + Home / End
ใน grid ที่แก้ไขได้ ย้ายระหว่างเซลล์
Enter, F2
ใน grid ที่แก้ไขได้ แก้ไขเซลล์ (หรือกดตัวควบคุมในเซลล์)
Escape
ยกเลิกการแก้ไข ล้างช่องค้นหา
Accessibility
ตารางมี role ของตาราง (table, rowgroup, row, columnheader, cell และเป็น grid เมื่อมีคอลัมน์ที่แก้ไขได้) คอลัมน์ที่เรียงอยู่มี aria-sort ตั้งชื่อตารางด้วย aria-label บน <ui-table>: เหมือน Carbon ชื่อตารางที่แสดงไม่ได้ผูกกับตาราง checkbox, radio และลูกศรของแต่ละแถวตั้งชื่อด้วยเซลล์แรกของแถว ("เลือกแถว, สัญญาบริการ")
ตารางที่เลื่อนได้ (sticky-header หรือกว้างกว่ากล่อง) รับ focus ได้เพื่อให้ผู้ใช้คีย์บอร์ดเลื่อนได้ และมีชื่อตาม aria-label หรือชื่อตาราง
ขณะ loading ตารางเป็น aria-busy และมีสถานะบอกว่า "กำลังโหลดข้อมูล" จำนวนในแถบ batch เป็น status จำนวนใหม่จึงถูกอ่านเมื่อเลือกแถว DataTable ของ React + Tailwind ยังบอก "เรียงตามคอลัมน์ สัญญา จากน้อยไปมาก" หลังกดเรียง และ "แสดง 3 จาก 12 แถว" เมื่อหยุดพิมพ์ค้นหา
grid ที่แก้ไขได้ทำตามแบบ grid ของ WAI-ARIA: เซลล์ที่แก้ไม่ได้เป็น aria-readonly และเซลล์ที่แก้ได้บอกว่า "กด Enter เพื่อแก้ไข"
ต้องการแค่พฤติกรรมโดยไม่มี style: Headless Data table
API
สร้างจากแพ็กเกจโดยตรง ใน React ส่ง property เป็น prop ชื่อเดียวกัน ส่วน event ก็เป็น prop เช่นกัน (ดูคอลัมน์ React)
<ui-table> · React UiTable
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
size
size
TableSize
'lg'
is-sortable
isSortable
boolean
false
Every header sorts the rows (Carbon is-sortable).
use-zebra-styles
useZebraStyles
boolean
false
Stripe every second body row (Carbon use-zebra-styles).
use-static-width
useStaticWidth
boolean
false
As wide as its content instead of its container (Carbon use-static-width).
locale
locale
string
''
The language text sorts in; empty: the page's lang.
is-selectable
isSelectable
boolean
false
A checkbox on every row and select-all in the header row (Carbon is-selectable).
radio
radio
boolean
false
One row at a time, with radios (Carbon radio).
expandable
expandable
boolean
false
Rows followed by a <ui-table-expanded-row> open it with a chevron (Carbon expandable).
batch-expansion
batchExpansion
boolean
false
An expand-all chevron in the header row (Carbon batch-expansion).
with-header
withHeader
boolean
false
The title / description block shows (set from the title / description slots, as Carbon).
resizable
resizable
boolean
false
A resize handle on every header (or resizable on single headers).
page-size
pageSize
number
0
Rows per page: above 0 a <ui-pagination> pages the rows the sort and search leave.
page
page
number
1
The page shown (from 1).
page-sizes
pageSizes
string
'10,25,50'
The page sizes the pagination offers (comma-separated).
loading
loading
boolean
false
Skeleton rows instead of the body while the data loads (the table is aria-busy).
loading-rows
loadingRows
number
0
How many skeleton rows loading shows (default: the rows shown now, else the page size, else 5).
sticky-header
stickyHeader
boolean
false
Keeps the header in view while the body scrolls inside a box (Carbon React stickyHeader; --ui-table-max-height, default 300px).
Property
Property
ชนิด
คำอธิบาย
filterRows
(rowText: string, searchString: string) => boolean
Whether the search leaves a row out: true hides it (Carbon filterRows; default: its text doesn't contain the search).
columns
UiTableHeaderCell[]
(อ่านอย่างเดียว) The column headers, in order (the column settings list them).
hiddenColumns
string[]
(อ่านอย่างเดียว) The keys of the hidden columns.
contentWidth
(อ่านอย่างเดียว) Width of the horizontal scroll box (a resize stops a column there).
selectedRows
UiTableRow[]
(อ่านอย่างเดียว) The chosen rows.
columnsChanged
(อ่านอย่างเดียว) Columns were shown or hidden since the markup (Reset has something to do).
columnWidths
Record<string, number>
(อ่านอย่างเดียว) The widths given or resized, by column.
csvFileName
(อ่านอย่างเดียว) The file name a CSV download takes by default: the title's text.
Method
Method
คำอธิบาย
customSortRow(lhs, rhs, collator)
Compares two cells' sort values (Carbon customSortRow) for ascending order: numbers by value, text with collator. Replace it on the element to sort another way.
isColumnLocked(column)
Whether column can't be hidden or shown now: not hideable, or the last one shown.
setColumnHidden(column, hidden)
Shows or hides a column (and its cells); false when it can't change (not hideable, or the last one shown).
resetColumns()
Back to the columns hidden in the markup.
freezeColumns()
The first resize freezes the automatic layout: every shown column keeps its width, a filler cell takes the rest of the row (none in a static-width table, which ends at its columns).
csvRows(scope)
The rows CSV takes: those the search shows (every page, in their order), the chosen ones, or all.
toCsv({ scope = 'shown' })
The columns shown and the rows of scope as CSV (a cell writes its csv-value, else its text).
downloadCsv({ scope = 'shown', fileName })
Downloads toCsv({ scope }) as fileName (default: the title, else "table"; .csv is added).
focus(options)
Focuses the table's first stop: the scroll box when it scrolls, else select-all, a sort button, the grid's Tab stop, or the first row's checkbox, radio or chevron.
Event
Event
React
คำอธิบาย
ui-table-columns-change
onUiTableColumnsChange
detail: { hiddenColumns, column, hidden } after a column was shown or hidden (column is '' after Reset)
ui-table-row-all-selected
onUiTableRowAllSelected
detail: { selectedRows } after select-all or Cancel
ui-table-sorted
onUiTableSorted
detail: { sortedHeader } after the rows were sorted by a header click
ui-table-row-selected
onUiTableRowSelected
detail: { selectedRow, selectedRows } after the user chose or released a row
ui-table-filtered
onUiTableFiltered
detail: { unfilteredRows } after the search changed which rows show
ui-table-page-change
onUiTablePageChange
detail: { page, pageSize } after the built-in pagination changed (page-size)
ui-table-cell-edit
onUiTableCellEdit
from the cell, cancelable; detail: { row, cell, column, value, previous } before an edited value is written into the cell (preventDefault() to write it yourself)
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
<ui-table-head> and <ui-table-body>
title
A <ui-table-header-title>
description
A <ui-table-header-description>
toolbar
A <ui-table-toolbar>
empty
Shown when there are no rows (default: "No data")
no-results
Shown when the search leaves no rows (default: "No results found. Try a different search.")
CSS part
Part
คำอธิบาย
header
The title / description block
content
The horizontal scroll container
table
The box laid out as a table
empty
The message under the headers when there are no rows
pagination
The built-in <ui-pagination> (page-size)
CSS custom property
Custom property
ค่าเริ่มต้น
คำอธิบาย
--ui-table-max-height
Height of the scrolling box with sticky-header (default 300px)
--ui-table-row-height
Row height of the default size, lg (default 48px; Kanok: 40px)
--ui-table-border
/ --ui-table-radius / --ui-table-overflow - A frame around the table (default none, 0, visible; Kanok: none, 12px, clip)
--ui-table-background
Fill of the table: its title, toolbar and rows (default transparent, rows --ui-surface-1; Kanok: the cards' fill)
--ui-table-header-rule
box-shadow under the header cells (default none; Kanok: a hairline)
<ui-table-head> · React UiTableHead
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
A <ui-table-header-row>
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
selected
selected
boolean
false
Chosen (Carbon selected); the table keeps the header's select-all and the batch actions in step.
disabled
disabled
boolean
false
Can't be chosen.
radio
radio
boolean
false
A single-choice radio instead of a checkbox (the table's radio sets it).
hide-checkbox
hideCheckbox
boolean
false
No checkbox in the selection cell (the header row of a radio table).
selection-name
selectionName
string
''
Shows the selection cell: the checkbox's name (the table's is-selectable sets one).
selection-value
selectionValue
string
''
The checkbox's value.
selection-label
selectionLabel
string
''
The checkbox's accessible name; default "Select row" with the row's first cell.
expandable
expandable
boolean
false
Has a <ui-table-expanded-row> after it (the table's expandable sets it).
expanded
expanded
boolean
false
Its expanded row is open.
batch-expansion
batchExpansion
boolean
false
The header row's chevron opens and closes every row (the table's batch-expansion sets it).
filtered
filtered
boolean
false
Left out by the table's search.
highlighted
highlighted
boolean
false
Hovered with its expanded row (the two tint together).
paged-out
pagedOut
boolean
false
On another page of the table's pagination (the table sets it).
Property
Property
ชนิด
คำอธิบาย
expandColumn
boolean
The table has an expand column: every row gets the cell, expandable ones the chevron.
indeterminate
boolean
The header's select-all is partly checked (some rows chosen); the table sets it.
tabStop
boolean
The radio of a radio table that takes Tab (the chosen row, else the first); the table sets it.
pinStart
boolean
The first column is pinned: the chevron and checkbox cells stick too (the table sets it).
filler
boolean
A filler cell after the cells takes the rest of the row once the columns are resized (the table sets it).
grid
boolean
The table is a grid (an editable column): grid cells, the body's cells and controls out of the Tab order (the table sets it).
Method
Method
คำอธิบาย
toggleExpanded(expanded)
Opens or closes, unless the cancelable ui-table-row-expando-beingtoggled is canceled.
gridCells()
The cells the grid's arrow keys move through: the chevron and checkbox cells, then the shown author cells.
focusSelection()
Focuses this row's selection control (a radio the arrow keys moved to).
Event
Event
React
คำอธิบาย
ui-table-change-selection-all
onUiTableChangeSelectionAll
cancelable; detail: { selected } before every row is chosen or released
ui-table-row-expando-beingtoggled
ไม่มี (ใช้ ref)
ui-table-row-expando-toggled
ไม่มี (ใช้ ref)
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The <ui-table-header-cell>s
CSS part
Part
คำอธิบาย
expand-cell
The cell of the expand chevron
expand-button
The chevron button
selection-cell
The cell of the checkbox or radio
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
is-sortable
isSortable
boolean
false
Sortable on its own (the table's is-sortable sets every header).
sort-active
sortActive
boolean
false
The column the rows are sorted by (set with the direction).
sort-cycle
sortCycle
TableSortCycle | undefined
The states each click steps through.
sort-direction
sortDirection
TableSortDirection | undefined
Sorted ascending, descending or not; a sortable header without one starts at none.
column
column
string
''
The column's name in events and the column settings (default: its place, "0", "1" …).
column-hidden
columnHidden
boolean
false
Hidden with its cells (the column settings set it; set it in the markup to start hidden).
hideable
hideable
boolean
true
Can be hidden from the column settings (hideable="false" keeps it shown).
pinned
pinned
'start' | 'end' | undefined
Stays in view while the table scrolls sideways: start on the first header, end on the last.
resizable
resizable
boolean
false
A resize handle on its end edge (the table's resizable sets every header).
width
width
number | undefined
The column's width in px (a resize sets it).
min-width
minWidth
number | undefined
The narrowest a resize makes it (default 50).
max-width
maxWidth
number | undefined
The widest a resize makes it (default: the table's width).
editable
editable
TableCellEditor | undefined
Its cells can be edited in place, with this editor (no Carbon counterpart; the table becomes a grid).
options
options
TableEditOption[]
[]
A select column's choices: the value saved and the label shown (JSON in the attribute).
Property
Property
ชนิด
คำอธิบาย
validate
(value: string | number, cell: HTMLElement) => string | undefined
Checks an edited value before it's saved: a message keeps the editor open and shows it.
labelText
(อ่านอย่างเดียว) The label as text (the button's title, the screen reader hint, the column settings).
columnKey
(อ่านอย่างเดียว) The column's key: column, else its place among the headers.
Event
Event
React
คำอธิบาย
ui-table-header-cell-sort
onUiTableHeaderCellSort
cancelable; detail: { oldSortDirection, sortDirection } before the column sorts (preventDefault() keeps the rows and this header as they are: sort the data yourself and set sort-direction)
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The header's label
CSS part
Part
คำอธิบาย
content
The box inside the header that holds its padding
sort-button
The button of a sortable header
label-text
The label
sort-icon
The sort arrow
resizer
The resize handle (an invisible range input over the end edge)
CSS custom property
Custom property
ค่าเริ่มต้น
คำอธิบาย
--ui-table-header-background
Fill of the header (default --ui-layer-accent; Kanok: the table's fill)
--ui-table-header-ink
Text colour of the header (default --ui-ink; Kanok: secondary text)
--ui-table-sort-hover
/ --ui-table-sorted-background / --ui-table-sorted-icon - A sortable header: hover fill, the sorted column's fill and arrow (default layer-selected-hover, icon-primary; Kanok: the header fill, an --ui-icon-interactive arrow)
<ui-table-body> · React UiTableBody
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
use-zebra-styles
useZebraStyles
boolean
false
Stripe every second row (the table passes its use-zebra-styles).
Method
Method
คำอธิบาย
updateZebra()
Marks the rows even / odd in document order (Carbon _updateZebra), counting only the rows shown (search, page).
Event
Event
React
คำอธิบาย
ui-table-body-content-change
onUiTableBodyContentChange
its rows were added, removed or reordered (the table listens)
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The <ui-table-row>s
<ui-table-row> · React UiTableRow
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
even
even
boolean
false
A striped row (set by the body with use-zebra-styles).
odd
odd
boolean
false
An unstriped row of a zebra table (set by the body).
selected
selected
boolean
false
Chosen (Carbon selected); the table keeps the header's select-all and the batch actions in step.
disabled
disabled
boolean
false
Can't be chosen.
radio
radio
boolean
false
A single-choice radio instead of a checkbox (the table's radio sets it).
hide-checkbox
hideCheckbox
boolean
false
No checkbox in the selection cell (the header row of a radio table).
selection-name
selectionName
string
''
Shows the selection cell: the checkbox's name (the table's is-selectable sets one).
selection-value
selectionValue
string
''
The checkbox's value.
selection-label
selectionLabel
string
''
The checkbox's accessible name; default "Select row" with the row's first cell.
expandable
expandable
boolean
false
Has a <ui-table-expanded-row> after it (the table's expandable sets it).
expanded
expanded
boolean
false
Its expanded row is open.
batch-expansion
batchExpansion
boolean
false
The header row's chevron opens and closes every row (the table's batch-expansion sets it).
filtered
filtered
boolean
false
Left out by the table's search.
highlighted
highlighted
boolean
false
Hovered with its expanded row (the two tint together).
paged-out
pagedOut
boolean
false
On another page of the table's pagination (the table sets it).
Property
Property
ชนิด
คำอธิบาย
expandColumn
boolean
The table has an expand column: every row gets the cell, expandable ones the chevron.
indeterminate
boolean
The header's select-all is partly checked (some rows chosen); the table sets it.
tabStop
boolean
The radio of a radio table that takes Tab (the chosen row, else the first); the table sets it.
pinStart
boolean
The first column is pinned: the chevron and checkbox cells stick too (the table sets it).
filler
boolean
A filler cell after the cells takes the rest of the row once the columns are resized (the table sets it).
grid
boolean
The table is a grid (an editable column): grid cells, the body's cells and controls out of the Tab order (the table sets it).
Method
Method
คำอธิบาย
toggleExpanded(expanded)
Opens or closes, unless the cancelable ui-table-row-expando-beingtoggled is canceled.
gridCells()
The cells the grid's arrow keys move through: the chevron and checkbox cells, then the shown author cells.
focusSelection()
Focuses this row's selection control (a radio the arrow keys moved to).
Event
Event
React
คำอธิบาย
ui-table-row-change-selection
onUiTableRowChangeSelection
cancelable; detail: { selected } before the row is chosen or released
ui-table-row-expando-beingtoggled
onUiTableRowExpandoBeingtoggled
cancelable; detail: { expanded } before the row opens or closes
ui-table-row-expando-toggled
onUiTableRowExpandoToggled
detail: { expanded } after the row opened or closed
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The row's <ui-table-cell>s
CSS part
Part
คำอธิบาย
expand-cell
The cell of the expand chevron
expand-button
The chevron button
selection-cell
The cell of the checkbox or radio
CSS custom property
Custom property
ค่าเริ่มต้น
คำอธิบาย
--ui-table-row-selected
Fill of a chosen row (default --ui-layer-accent; Kanok: --ui-highlight)
--ui-table-row-thread
background-image of a chosen row's first cell, for a mark on its start edge (default none; Kanok: a 3px --ui-border-interactive mark)
--ui-icon-control-radius
Corners of its small icon buttons, their hover fill and ring (default 0; Kanok: round)
<ui-table-cell> · React UiTableCell
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
column-hidden
columnHidden
boolean
false
Its column is hidden (the table follows the header's column-hidden).
pinned
pinned
'start' | 'end' | undefined
Its column is pinned (the table follows the header's pinned).
editable
editable
TableCellEditor | undefined
Its column's editor (the table follows the header's editable).
editing
editing
boolean
false
The editor is open (the table sets it).
Property
Property
ชนิด
คำอธิบาย
draft
string
The editor's text while editing (the table sets where it starts).
editorLabel
string
The editor's name for screen readers: the column and the row (the table sets it).
editorOptions
TableEditOption[]
A select editor's choices (the header's options).
editorError
string
The header's validate message for the value in the editor.
editorValue
(อ่านอย่างเดียว) What the editor holds now.
Method
Method
คำอธิบาย
focusEditor(select)
Focuses the open editor; select selects a text editor's text (else the caret goes to the end).
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The cell's content
CSS part
Part
คำอธิบาย
content
The box inside the cell that holds its padding
edit-icon
The pencil of an editable cell
editor
The input or select while editing
error
The validate message under the editor
CSS custom property
Custom property
ค่าเริ่มต้น
คำอธิบาย
--ui-table-cell-ink
Text colour of a row at rest (default --ui-ink-muted; Kanok: --ui-ink)
<ui-table-expanded-row> · React UiTableExpandedRow
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
colspan
colSpan
number
1
How many columns it spans (the table sets it).
expanded
expanded
boolean
false
Shown (follows the row before it).
filtered
filtered
boolean
false
Left out by the table's search, with its row.
paged-out
pagedOut
boolean
false
On another page, with its row.
highlighted
highlighted
boolean
false
Hovered with its row.
selected
selected
boolean
false
Its row is chosen.
Property
Property
ชนิด
คำอธิบาย
grid
boolean
The table is a grid (an editable column): a grid cell (the table sets it).
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The content
CSS part
Part
คำอธิบาย
cell
The full-width cell
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The title
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The description
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
<ui-table-batch-actions> and <ui-table-toolbar-content>
<ui-table-toolbar-content> · React UiTableToolbarContent
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
has-batch-actions
hasBatchActions
boolean
false
The batch actions are showing (rows are chosen).
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The controls
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
persistent
persistent
boolean
false
Always open (Carbon persistent).
label
label
string
''
Accessible name of the field (visually hidden, as in Carbon).
placeholder
placeholder
string
''
value
value
string
''
name
name
string
''
Reflected: form-associated elements submit under the name attribute.
size
size
SearchSize
'md'
Field height: sm 32px, md 40px, lg 48px (tokens --ui-field-height-*).
disabled
disabled
boolean
false
Disables the control; a disabled <fieldset> ancestor does the same.
autocomplete
autocomplete
string
'off'
inputmode
inputmode
string
''
Passed to the text box: the virtual keyboard to show (numeric, decimal, email, tel, url, search…).
enterkeyhint
enterkeyhint
string
''
Passed to the text box: the label of the virtual keyboard's Enter key (search, send, next, done…).
clear-label
clearLabel
string
''
Accessible name of the clear button.
required
required
boolean
false
Constraint validation like <input type="search">: blocks submit and reports in the browser's bubble (Carbon Search has no error line).
pattern
pattern
string
''
minlength
minlength
number | undefined
maxlength
maxlength
number | undefined
readonly
readonly
boolean
false
Value can be selected and submitted but not changed; no clear button.
fluid
fluid
boolean
false
Carbon FluidSearch: the label inside a 64px box. <ui-fluid-form> sets it for every field inside.
expandable
expandable
boolean
false
Carbon ExpandableSearch: collapsed to its magnifier until opened.
expanded
expanded
boolean
false
Whether an expandable search is open.
Property
Property
ชนิด
คำอธิบาย
willValidate
(อ่านอย่างเดียว) Whether the field takes part in constraint validation (not while disabled), as natively.
labels
(อ่านอย่างเดียว) The <label>s that point at this field.
Method
Method
คำอธิบาย
setCustomValidity(message)
Like <input>.setCustomValidity(): a non-empty message makes the field invalid until cleared with ''.
clear()
Empties the field, keeps focus in it and announces the change (input, change, ui-clear).
Event
Event
React
คำอธิบาย
change
onChange
When the value is committed (blur / Enter) or cleared
ui-toggle
onUiToggle
detail: { expanded } when an expandable search opens or collapses
input
onInput
On every keystroke
ui-clear
onUiClear
After the clear button or Esc emptied the field
CSS part
Part
คำอธิบาย
base
The role=search wrapper
input
The native search input
label
The label (visually hidden, as in Carbon; shown inside the box when fluid)
magnifier
The search icon
clear-button
The clear button
magnifier-button
The magnifier of an expandable search
CSS custom property
Custom property
ค่าเริ่มต้น
คำอธิบาย
--ui-field-open-background
The box's fill while a search is under way (default the layer's field fill)
--ui-field-border
Border on every side of the box (default none: Carbon's underline only; Kanok: a 1px outline)
--ui-field-disabled-border-color
Border colour when disabled (default: the underline transparent)
--ui-field-readonly-border-color
Border colour when read-only (default: a hairline underline)
--ui-field-radius
Corner radius of the box (default 0; Kanok: 6px)
--ui-field-background
Fill of the box (default --ui-surface-1; Kanok: transparent)
--ui-label-font
Font of the label (default --ui-font-caption; Kanok: 14px semibold)
--ui-label-color
Colour of the label (default --ui-ink-muted; Kanok: --ui-ink)
--ui-icon-control-radius
Corners of its small icon buttons, their hover fill and ring (default 0; Kanok: round)
<ui-table-batch-actions> · React UiTableBatchActions
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
active
active
boolean
false
Showing over the toolbar (rows are chosen).
selected-rows-count
selectedRowsCount
number
0
How many rows are chosen (the table sets it; set it yourself for a selection kept across pages).
total-rows-count
totalRowsCount
number
0
Every row there is (server paging): above the count, "Select all (N)" shows.
size
size
'xs' | 'sm' | 'lg'
'lg'
The table's size, normalized to xs / sm / lg (the table sets it): sizes the action buttons.
Property
Property
ชนิด
คำอธิบาย
formatSelectedItemsCount
(options: { count: number }) => string | undefined
The count text (Carbon formatSelectedItemsCount); default: the translation.
Event
Event
React
คำอธิบาย
ui-table-batch-actions-cancel-clicked
onUiTableBatchActionsCancelClicked
Cancel was clicked (the table releases every row)
ui-table-batch-actions-select-all-clicked
onUiTableBatchActionsSelectAllClicked
"Select all (N)" was clicked
Slot
Slot
คำอธิบาย
(ค่าเริ่มต้น)
The actions (<ui-button>s; the bar sizes them to the toolbar)
cancel-button-content
Cancel's text (default: the translation)
select-all-button-content
"Select all (N)"'s text
CSS part
Part
คำอธิบาย
batch-summary
The selected-count text
select-all-button
"Select all (N)"
cancel-button
Cancel
CSS custom property
Custom property
ค่าเริ่มต้น
คำอธิบาย
--ui-batch-background
/ --ui-batch-ink / --ui-batch-divider - The bar's fill, text and the rule before Cancel (default Carbon's brand bar: background-brand, text-on-color)
--ui-batch-button
/ --ui-batch-button-ink / --ui-batch-button-hover / --ui-batch-button-active / --ui-batch-focus - Its buttons and their focus ring (default the primary button's colours, a layer-coloured ring)
<ui-table-column-settings> · React UiTableColumnSettings
CSS part
Part
คำอธิบาย
button
The toolbar action
panel
The "Columns" list
<ui-table-csv-export> · React UiTableCsvExport
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
file-name
fileName
string
''
The downloaded file's name (.csv is added); default: the table's title, else "table".
Event
Event
React
คำอธิบาย
ui-table-csv-export
onUiTableCsvExport
cancelable; detail: { csv, rows, fileName } before the download
CSS part
Part
คำอธิบาย
button
The toolbar action
<ui-table-skeleton> · React UiTableSkeleton
Attribute
Attribute
Property
ชนิด
ค่าเริ่มต้น
คำอธิบาย
column-count
columnCount
number
5
row-count
rowCount
number
5
show-header
showHeader
boolean
true
The title / description bars (Carbon show-header; show-header="false" hides them).
show-toolbar
showToolbar
boolean
true
The toolbar bar (Carbon show-toolbar; show-toolbar="false" hides it).
zebra
zebra
boolean
false
Stripe every second row.
Property
Property
ชนิด
คำอธิบาย
headers
string[]
Header texts to show instead of bars (Carbon headers); their number sets the columns.
CSS part
Part
คำอธิบาย
table
The <table>