ตารางข้อมูล
DataTable
A complete data table from columns and rows: a filter bar with search, filter chips, sortable headings, paging, row selection with bulk actions, a total row, and the loading, error, first-use and no-results states. At phone width each row becomes a labelled block. Pass all rows and the table searches, sorts and pages them itself. For a list the core API pages, pass total and handle onSortChange, search.onChange and onPageChange with a new query. For a record's own lines, such as the items of a purchase request, pass paged false and the record's total in totals.
ใช้แสดงรายการข้อมูลทุกแบบ หน้าจอส่งคอลัมน์และแถวเป็นข้อมูล แล้วตารางจัดการค้นหา เรียงลำดับ แบ่งหน้า เลือกหลายแถว แถวรวม และสถานะต่าง ๆ เอง หน้าจอไม่ต้องเขียน <table> หรือคลาสของแนวทางการออกแบบ ถ้าวางบน Card ให้อยู่ใน DashedContainer ถ้าทุกแถวอยู่ในหน้าจอแล้ว ส่ง rows ทั้งหมด ถ้า API ของ core แบ่งหน้าให้ ส่ง total และรับการเปลี่ยนแปลงเพื่อดึงข้อมูลใหม่
import { DataTable } from "@bsru/ui";ตัวอย่าง
ตารางจากข้อมูลอย่างเดียว
ส่งคอลัมน์และแถวทั้งหมด ตารางค้นหา เรียง และแบ่งหน้าเอง kind บอกวิธีแสดงค่า: money แสดงทศนิยมสองตำแหน่ง date แสดงปีพุทธศักราช badge แปลงค่าเป็นป้ายสถานะ ตารางข้อมูลด้านล่างแสดงสามแถวแรกจาก 23 แถว
พบ 23 คำขอ
| PR-2570-0023 | เครื่องฉายภาพ | ห้างหุ้นส่วน สมมติV-0002 | 11 พ.ย. 2569 | 43,400.00 | รออนุมัติ |
| PR-2570-0022 | ค่าเช่าซอฟต์แวร์ | บริษัท ทดสอบ จำกัดV-0001 | 8 ต.ค. 2569 | 69,250.00 | ไม่อนุมัติ |
| PR-2570-0021 | หมึกพิมพ์ | ร้าน ตัวอย่างการค้าV-0003 | 5 ธ.ค. 2569 | 17,750.00 | ร่าง |
| PR-2570-0020 | โต๊ะและเก้าอี้ห้องเรียน | ห้างหุ้นส่วน สมมติV-0002 | 2 พ.ย. 2569 | 90,750.00 | อนุมัติแล้ว |
| PR-2570-0019 | จ้างซ่อมเครื่องปรับอากาศ | บริษัท ทดสอบ จำกัดV-0001 | 27 ต.ค. 2569 | 46,500.00 | รออนุมัติ |
| PR-2570-0018 | วัสดุสำนักงาน | ร้าน ตัวอย่างการค้าV-0003 | 24 ธ.ค. 2569 | 22,750.00 | อนุมัติแล้ว |
| PR-2570-0017 | ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง | ห้างหุ้นส่วน สมมติV-0002 | 21 พ.ย. 2569 | 154,000.00 | รออนุมัติ |
| PR-2570-0016 | จ้างทำความสะอาด | บริษัท ทดสอบ จำกัดV-0001 | 18 ต.ค. 2569 | 98,750.00 | ไม่อนุมัติ |
| PR-2570-0015 | เครื่องฉายภาพ | ร้าน ตัวอย่างการค้าV-0003 | 15 ธ.ค. 2569 | 41,400.00 | ร่าง |
| PR-2570-0014 | ค่าเช่าซอฟต์แวร์ | ห้างหุ้นส่วน สมมติV-0002 | 12 พ.ย. 2569 | 67,250.00 | อนุมัติแล้ว |
| รวมทุกหน้า | 1,486,700.00 | ||||
const columns: DataColumn<Request>[] = [
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
];
<DataTable
caption="คำขอซื้อขอจ้าง"
columns={columns}
rows={rows}
rowKey="no"
search={{ placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย" }}
defaultSort={{ key: "no", dir: "desc" }}
noun="คำขอ"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "คำขอซื้อขอจ้าง" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 6 รายการ[
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
] | readonly DataColumn<R>[] | — |
| rowKey* จำเป็น | "no" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| search | { placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย" } | TableSearch | false | The search box. Without total, the table searches the searchable columns itself, and shows the box even when this is left out, with ค้นหา (Search) as its placeholder. With total the core API pages the list, so pass a search with onChange to get a box. false hides it. A table with paged false shows one only when this is passed. |
| defaultSort | { key: "no", dir: "desc" } | TableSort | The sort on first render, when the table keeps it. |
| noun | "คำขอ" | string | The record name in the result count, such as รายการ or คำขอ. |
| rows* จำเป็น | รายการ 3 รายการ[
{
no: "PR-2570-0001",
item: [
"ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง",
"Notebook computers, 5 units",
],
unit: "หน่วยงาน ก",
vendor: "บริษัท ทดสอบ จำกัด",
vendorCode: "V-0001",
date: "2026-10-01",
amount: 150000,
status: "pending",
},
{
no: "PR-2570-0002",
item: ["วัสดุสำนักงาน", "Office supplies"],
unit: "หน่วยงาน ข",
vendor: "ห้างหุ้นส่วน สมมติ",
vendorCode: "V-0002",
date: "2026-11-04",
amount: 18750,
status: "approved",
},
{
no: "PR-2570-0003",
item: ["จ้างซ่อมเครื่องปรับอากาศ", "Air conditioner repair"],
unit: "หน่วยงาน ค",
vendor: "ร้าน ตัวอย่างการค้า",
vendorCode: "V-0003",
date: "2026-12-07",
amount: 42500,
status: "draft",
},
] | readonly R[] | All rows. With total set, only the rows of the current page. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
เลือกหลายแถวและเปิดรายการ
selection เพิ่มช่องเลือกในทุกแถวและแถบคำสั่งเมื่อมีแถวที่เลือก onRun ได้รับรหัสของทุกแถวที่เลือก onOpen ทำให้ค่าในคอลัมน์ที่มี opens กดได้ และเพิ่มปุ่มดูรายละเอียด ได้รับแถวนั้น หน้าจอเก็บแถวไว้ใน state แล้วแสดงใน Drawer ลองกดเลขที่หรือปุ่มดูรายละเอียด ใช้ openHref แทนเมื่อเปิดเป็นหน้าใหม่
พบ 23 คำขอ
| จัดการ | |||||||
|---|---|---|---|---|---|---|---|
| ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง | บริษัท ทดสอบ จำกัดV-0001 | 1 ต.ค. 2569 | 150,000.00 | รออนุมัติ | |||
| วัสดุสำนักงาน | ห้างหุ้นส่วน สมมติV-0002 | 4 พ.ย. 2569 | 18,750.00 | อนุมัติแล้ว | |||
| จ้างซ่อมเครื่องปรับอากาศ | ร้าน ตัวอย่างการค้าV-0003 | 7 ธ.ค. 2569 | 42,500.00 | ร่าง | |||
| โต๊ะและเก้าอี้ห้องเรียน | บริษัท ทดสอบ จำกัดV-0001 | 10 ต.ค. 2569 | 86,750.00 | ไม่อนุมัติ | |||
| หมึกพิมพ์ | ห้างหุ้นส่วน สมมติV-0002 | 13 พ.ย. 2569 | 13,750.00 | รออนุมัติ | |||
| ค่าเช่าซอฟต์แวร์ | ร้าน ตัวอย่างการค้าV-0003 | 16 ธ.ค. 2569 | 65,250.00 | อนุมัติแล้ว | |||
| เครื่องฉายภาพ | บริษัท ทดสอบ จำกัดV-0001 | 19 ต.ค. 2569 | 39,400.00 | รออนุมัติ | |||
| จ้างทำความสะอาด | ห้างหุ้นส่วน สมมติV-0002 | 22 พ.ย. 2569 | 96,750.00 | อนุมัติแล้ว | |||
| ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง | ร้าน ตัวอย่างการค้าV-0003 | 25 ธ.ค. 2569 | 152,000.00 | ร่าง | |||
| วัสดุสำนักงาน | บริษัท ทดสอบ จำกัดV-0001 | 28 ต.ค. 2569 | 20,750.00 | ไม่อนุมัติ | |||
| รวมทุกหน้า | 1,486,700.00 | ||||||
const columns: DataColumn<Request>[] = [
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
];
const actions: BulkAction[] = [
{ label: "ส่งออก", icon: Download, onRun: (keys) => exportRequests(keys) },
];
// The row the drawer shows, or null while it's closed.
const [opened, setOpened] = useState<Request | null>(null);
<DataTable
caption="คำขอซื้อขอจ้าง"
columns={columns}
rows={rows}
rowKey="no"
search={{ placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย" }}
selection={{ actions }}
onOpen={setOpened}
noun="คำขอ"
/>
<Drawer
open={opened !== null}
onClose={() => setOpened(null)}
title={opened?.no ?? ""}
summary={opened && {
title: opened.item,
// The same badge as the status column: { tone, icon, label } for this status.
status: badges[opened.status],
figure: { label: "วงเงิน", value: money(opened.amount), unit: "บาท" },
}}
>
{opened ? (
<RecordSection title="รายละเอียด">
<FieldList fields={requestFields(opened)} />
</RecordSection>
) : null}
</Drawer>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "คำขอซื้อขอจ้าง" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 6 รายการ[
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
] | readonly DataColumn<R>[] | — |
| rowKey* จำเป็น | "no" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| search | { placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย" } | TableSearch | false | The search box. Without total, the table searches the searchable columns itself, and shows the box even when this is left out, with ค้นหา (Search) as its placeholder. With total the core API pages the list, so pass a search with onChange to get a box. false hides it. A table with paged false shows one only when this is passed. |
| selection | ออบเจกต์ 1 ฟิลด์{ actions: [{ label: "ส่งออก", icon: Download, onRun: () => {} }] } | TableSelection | Adds a checkbox to each row, and a bar of actions while any row is chosen. |
| noun | "คำขอ" | string | The record name in the result count, such as รายการ or คำขอ. |
| rows* จำเป็น | รายการ 3 รายการ[
{
no: "PR-2570-0001",
item: [
"ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง",
"Notebook computers, 5 units",
],
unit: "หน่วยงาน ก",
vendor: "บริษัท ทดสอบ จำกัด",
vendorCode: "V-0001",
date: "2026-10-01",
amount: 150000,
status: "pending",
},
{
no: "PR-2570-0002",
item: ["วัสดุสำนักงาน", "Office supplies"],
unit: "หน่วยงาน ข",
vendor: "ห้างหุ้นส่วน สมมติ",
vendorCode: "V-0002",
date: "2026-11-04",
amount: 18750,
status: "approved",
},
{
no: "PR-2570-0003",
item: ["จ้างซ่อมเครื่องปรับอากาศ", "Air conditioner repair"],
unit: "หน่วยงาน ค",
vendor: "ร้าน ตัวอย่างการค้า",
vendorCode: "V-0003",
date: "2026-12-07",
amount: 42500,
status: "draft",
},
] | readonly R[] | All rows. With total set, only the rows of the current page. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | setOpened | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
แถบตัวกรองและชิปตัวกรอง
ตัวกรองอยู่บนแถบเหนือตารางเสมอ เรียงจากซ้าย ช่องค้นหาอยู่ทางขวา กว้างราวหนึ่งในห้าของตาราง ไม่มีปุ่มให้กดเปิดก่อน ใช้ช่องแบบกะทัดรัด: Segmented ที่มีจำนวนในแต่ละตัวเลือก และ Select, Combobox หรือ DateInput ที่ใส่ hideLabel พร้อม placeholder ที่บอกชื่อตัวกรอง หน้าจอเก็บตัวกรองไว้เอง กรองแถว แล้วส่งชิปของตัวกรองที่ใช้อยู่
พบ 8 คำขอ
หน่วยงาน
| PR-2570-0001 | ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง | บริษัท ทดสอบ จำกัดV-0001 | 1 ต.ค. 2569 | 150,000.00 | รออนุมัติ |
| PR-2570-0004 | โต๊ะและเก้าอี้ห้องเรียน | บริษัท ทดสอบ จำกัดV-0001 | 10 ต.ค. 2569 | 86,750.00 | ไม่อนุมัติ |
| PR-2570-0007 | เครื่องฉายภาพ | บริษัท ทดสอบ จำกัดV-0001 | 19 ต.ค. 2569 | 39,400.00 | รออนุมัติ |
| PR-2570-0010 | วัสดุสำนักงาน | บริษัท ทดสอบ จำกัดV-0001 | 28 ต.ค. 2569 | 20,750.00 | ไม่อนุมัติ |
| PR-2570-0013 | หมึกพิมพ์ | บริษัท ทดสอบ จำกัดV-0001 | 9 ต.ค. 2569 | 15,750.00 | รออนุมัติ |
| PR-2570-0016 | จ้างทำความสะอาด | บริษัท ทดสอบ จำกัดV-0001 | 18 ต.ค. 2569 | 98,750.00 | ไม่อนุมัติ |
| PR-2570-0019 | จ้างซ่อมเครื่องปรับอากาศ | บริษัท ทดสอบ จำกัดV-0001 | 27 ต.ค. 2569 | 46,500.00 | รออนุมัติ |
| PR-2570-0022 | ค่าเช่าซอฟต์แวร์ | บริษัท ทดสอบ จำกัดV-0001 | 8 ต.ค. 2569 | 69,250.00 | ไม่อนุมัติ |
| รวมทุกหน้า | 527,150.00 | ||||
const [status, setStatus] = useState<StatusFilter>("all");
const [unit, setUnit] = useState<string | null>(null);
const [dates, setDates] = useState(""); // 2026-11-01/2026-11-30
const scoped = rows.filter((r) => matchesUnit(r, unit) && inRange(r.date, dates));
const shown = status === "all" ? scoped : scoped.filter((r) => r.status === status);
const chips: FilterChip[] = [
...(unit ? [{ key: "unit", label: unit, onRemove: () => setUnit(null) }] : []),
...(dates ? [{ key: "dates", label: rangeLabel(dates), onRemove: () => setDates("") }] : []),
];
<DataTable
caption="คำขอซื้อขอจ้าง"
columns={columns}
rows={shown}
rowKey="no"
search={{ placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย" }}
filters={{
chips,
active: status !== "all", // the Segmented has no chip
onClearAll: () => {
setStatus("all");
setUnit(null);
setDates("");
},
panel: (
<>
{/* statusChoices gives ทั้งหมด and each status, with the count of scoped rows in it. */}
<Segmented label="สถานะ" value={status} options={statusChoices(scoped)} onChange={setStatus} />
<Select hideLabel label="หน่วยงาน" placeholder="ทุกหน่วยงาน"
options={unitOptions} value={unit} onChange={setUnit} />
<DateInput hideLabel kind="range" label="ช่วงวันที่" placeholder="ทุกวันที่"
value={dates} onValueChange={setDates} />
</>
),
}}
noun="คำขอ"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "คำขอซื้อขอจ้าง" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 6 รายการ[
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
] | readonly DataColumn<R>[] | — |
| rowKey* จำเป็น | "no" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| search | { placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย" } | TableSearch | false | The search box. Without total, the table searches the searchable columns itself, and shows the box even when this is left out, with ค้นหา (Search) as its placeholder. With total the core API pages the list, so pass a search with onChange to get a box. false hides it. A table with paged false shows one only when this is passed. |
| filters | ออบเจกต์ 3 ฟิลด์{
chips: [{ key: "unit", label: "หน่วยงาน ก", onRemove: () => {} }],
onClearAll: () => {},
panel: <>
<Segmented
label="สถานะ"
value="all"
options={[
{ value: "all", label: "ทั้งหมด", count: 23 },
{ value: "draft", label: "ร่าง", count: 4 },
{ value: "pending", label: "รออนุมัติ", count: 8 },
{ value: "approved", label: "อนุมัติแล้ว", count: 7 },
{ value: "rejected", label: "ไม่อนุมัติ", count: 4 },
]}
onChange={handleChange}
/>
<Select
hideLabel
label="หน่วยงาน"
placeholder="ทุกหน่วยงาน"
options={[
{ value: "หน่วยงาน ก", label: "หน่วยงาน ก" },
{ value: "หน่วยงาน ข", label: "หน่วยงาน ข" },
{ value: "หน่วยงาน ค", label: "หน่วยงาน ค" },
]}
value="หน่วยงาน ก"
onChange={handleChange}
/>
<DateInput
hideLabel
kind="range"
label="ช่วงวันที่"
placeholder="ทุกวันที่"
value=""
onValueChange={handleValueChange}
/>
</>,
} | TableFilters | The filters in the filter bar, on the left of the search box, and their chips under it. The screen filters the rows. |
| noun | "คำขอ" | string | The record name in the result count, such as รายการ or คำขอ. |
| rows* จำเป็น | รายการ 3 รายการ[
{
no: "PR-2570-0001",
item: [
"ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง",
"Notebook computers, 5 units",
],
unit: "หน่วยงาน ก",
vendor: "บริษัท ทดสอบ จำกัด",
vendorCode: "V-0001",
date: "2026-10-01",
amount: 150000,
status: "pending",
},
{
no: "PR-2570-0002",
item: ["วัสดุสำนักงาน", "Office supplies"],
unit: "หน่วยงาน ข",
vendor: "ห้างหุ้นส่วน สมมติ",
vendorCode: "V-0002",
date: "2026-11-04",
amount: 18750,
status: "approved",
},
{
no: "PR-2570-0003",
item: ["จ้างซ่อมเครื่องปรับอากาศ", "Air conditioner repair"],
unit: "หน่วยงาน ค",
vendor: "ร้าน ตัวอย่างการค้า",
vendorCode: "V-0003",
date: "2026-12-07",
amount: 42500,
status: "draft",
},
] | readonly R[] | All rows. With total set, only the rows of the current page. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
ตัวกรองที่ไม่พบรายการ
ตัวกรองที่ไม่มีชิป เช่น Segmented ที่ไม่ได้อยู่ที่ ทั้งหมด ก็กรองรายการอยู่ ให้ส่ง active เมื่อมีตัวกรองแบบนี้ใช้อยู่ เมื่อไม่มีแถว ตารางจะบอกว่าไม่พบรายการที่ตรงกับเงื่อนไข คงแถบตัวกรองไว้ และมีปุ่มล้างทั้งหมด แทนที่จะแสดงหน้าว่างเหมือนยังไม่มีข้อมูล ในตัวอย่างนี้ไม่มีคำขอที่เป็นร่าง และไม่มีชิป จึงมีปุ่มล้างทั้งหมดท้ายแถบตัวกรอง
พบ 0 คำขอ
หน่วยงาน
ไม่พบรายการที่ตรงกับเงื่อนไข ลองใช้คำค้นอื่น หรือล้างการค้นหาและเงื่อนไข | |||||
<DataTable
caption="คำขอซื้อขอจ้าง"
columns={columns}
rows={shown} // none: there are no drafts
rowKey="no"
empty={{ title: "ยังไม่มีคำขอซื้อขอจ้าง", body: "คำขอที่คุณสร้างจะแสดงที่นี่" }}
filters={{
chips,
active: status !== "all",
onClearAll: () => {
setStatus("all");
setUnit(null);
},
panel: <Segmented label="สถานะ" value={status} options={statusChoices(scoped)} onChange={setStatus} />,
}}
noun="คำขอ"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "คำขอซื้อขอจ้าง" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 6 รายการ[
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
] | readonly DataColumn<R>[] | — |
| rowKey* จำเป็น | "no" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| search | { placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย" } | TableSearch | false | The search box. Without total, the table searches the searchable columns itself, and shows the box even when this is left out, with ค้นหา (Search) as its placeholder. With total the core API pages the list, so pass a search with onChange to get a box. false hides it. A table with paged false shows one only when this is passed. |
| filters | ออบเจกต์ 4 ฟิลด์{
chips: [],
active: true,
onClearAll: () => {},
panel: <Segmented
label="สถานะ"
value="draft"
options={[
{ value: "all", label: "ทั้งหมด", count: 19 },
{ value: "draft", label: "ร่าง", count: 0 },
{ value: "pending", label: "รออนุมัติ", count: 8 },
{ value: "approved", label: "อนุมัติแล้ว", count: 7 },
{ value: "rejected", label: "ไม่อนุมัติ", count: 4 },
]}
onChange={handleChange}
/>,
} | TableFilters | The filters in the filter bar, on the left of the search box, and their chips under it. The screen filters the rows. |
| noun | "คำขอ" | string | The record name in the result count, such as รายการ or คำขอ. |
| empty | ออบเจกต์ 2 ฟิลด์{ title: "ยังไม่มีคำขอซื้อขอจ้าง", body: "คำขอที่คุณสร้างจะแสดงที่นี่" } | TableEmpty | What to show when there are no records at all, and nobody is searching or filtering. |
| rows* จำเป็น | [] | readonly R[] | All rows. With total set, only the rows of the current page. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
รายการที่ API ของ core แบ่งหน้า
ส่ง total เมื่อ API แบ่งหน้าให้ ตารางจะแสดงแถวตามที่ได้รับ และแจ้งการค้นหา (หลังหยุดพิมพ์ครู่หนึ่ง) การเรียง หน้า และจำนวนต่อหน้า ให้หน้าจอดึงข้อมูลใหม่ totals คือยอดรวมจาก API ตัวอย่างนี้จำลองการรอ API ครึ่งวินาที
กำลังโหลด
| ผู้ขาย | |||||
|---|---|---|---|---|---|
const [q, setQ] = useState("");
const [sort, setSort] = useState<TableSort>();
const [page, setPage] = useState(1);
const [size, setSize] = useState(10);
// Fetches GET /api/requests?q=&sort=&page=&size= again whenever these change.
const result = useRequests({ q, sort, page, size });
<DataTable
caption="คำขอซื้อขอจ้าง"
columns={columns}
rows={result?.rows ?? []}
rowKey="no"
total={result?.total ?? 0}
totals={{ amount: result?.sum ?? 0 }}
status={result ? "ready" : "loading"}
search={{ placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย", value: q, onChange: setQ }}
sort={sort}
onSortChange={setSort}
page={page}
onPageChange={setPage}
pageSize={size}
onPageSizeChange={setSize}
noun="คำขอ"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "คำขอซื้อขอจ้าง" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 6 รายการ[
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
] | readonly DataColumn<R>[] | — |
| rowKey* จำเป็น | "no" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| rows* จำเป็น | รายการ 3 รายการ[
{
no: "PR-2570-0001",
item: [
"ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง",
"Notebook computers, 5 units",
],
unit: "หน่วยงาน ก",
vendor: "บริษัท ทดสอบ จำกัด",
vendorCode: "V-0001",
date: "2026-10-01",
amount: 150000,
status: "pending",
},
{
no: "PR-2570-0002",
item: ["วัสดุสำนักงาน", "Office supplies"],
unit: "หน่วยงาน ข",
vendor: "ห้างหุ้นส่วน สมมติ",
vendorCode: "V-0002",
date: "2026-11-04",
amount: 18750,
status: "approved",
},
{
no: "PR-2570-0003",
item: ["จ้างซ่อมเครื่องปรับอากาศ", "Air conditioner repair"],
unit: "หน่วยงาน ค",
vendor: "ร้าน ตัวอย่างการค้า",
vendorCode: "V-0003",
date: "2026-12-07",
amount: 42500,
status: "draft",
},
] | readonly R[] | All rows. With total set, only the rows of the current page. |
| total | 23 | number | How many rows match on the server, for a list the core API pages. The table then shows rows as given. |
| totals | { amount: 1734000 } | Readonly<Partial<Record<keyof R & string, number>>> | Totals from the core API, by column key, shown in the total row. Pass them for a list the core API pages, and for a record's lines, so the total matches the record's amount. A total column without one here is added up from the rows, except in a list the core API pages. |
| status | "ready" | "ready" | "loading" | "error" ค่าที่ใช้ได้: "ready""loading""error" | loading shows placeholder rows, error shows the error. ready by default. |
| search | ออบเจกต์ 3 ฟิลด์{
placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย",
value: "",
onChange: () => {},
} | TableSearch | false | The search box. Without total, the table searches the searchable columns itself, and shows the box even when this is left out, with ค้นหา (Search) as its placeholder. With total the core API pages the list, so pass a search with onChange to get a box. false hides it. A table with paged false shows one only when this is passed. |
| page | 1 | number | The page shown, from 1, when the screen keeps it. |
| pageSize | 10 | number | Rows per page, when the screen keeps it. 10 by default. |
| onSortChange | setSort | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | setPage | (next: number) => void | — |
| onPageSizeChange | setSize | (next: number) => void | — |
| onOpen | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
รายการของเอกสารหนึ่งฉบับ
รายการสินค้าหรือบริการของคำขอหนึ่งฉบับ เช่น ในแท็บรายการหรือ RecordSection paged={false} แสดงทุกแถวโดยไม่มีข้อความช่วงรายการ ขนาดหน้า หรือตัวแบ่งหน้า unit แสดงหน่วยต่อจากจำนวน และ totals ส่งยอดรวมจาก core API ให้ตรงกับยอดของคำขอ
พบ 3 รายการ
| รายการ | จำนวน | ราคาต่อหน่วย | จำนวนเงิน (บาท) |
|---|---|---|---|
| คอมพิวเตอร์โน้ตบุ๊ก | 5 เครื่อง | 27,000.00 | 135,000.00 |
| กระเป๋าใส่โน้ตบุ๊ก | 5 ใบ | 1,000.00 | 5,000.00 |
| ติดตั้งและตั้งค่าซอฟต์แวร์ | 1 งาน | 10,000.00 | 10,000.00 |
| รวมทั้งสิ้น | 150,000.00 | ||
const lineColumns: DataColumn<Line>[] = [
{ key: "description", label: "รายการ" },
{ key: "quantity", label: "จำนวน", kind: "number", unit: "unit" },
{ key: "unitPrice", label: "ราคาต่อหน่วย", kind: "money" },
{
key: "amount",
label: "จำนวนเงิน (บาท)",
kind: "money",
total: true,
},
];
<DataTable
caption="รายการในคำขอ PR-2570-0001"
columns={lineColumns}
rows={record.lines}
rowKey="key"
paged={false}
totals={{ amount: record.total }}
totalLabel="รวมทั้งสิ้น"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "รายการในคำขอ PR-2570-0001" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 4 รายการ[
{ key: "description", label: "รายการ" },
{ key: "quantity", label: "จำนวน", kind: "number", unit: "unit" },
{ key: "unitPrice", label: "ราคาต่อหน่วย", kind: "money" },
{
key: "amount",
label: "จำนวนเงิน (บาท)",
kind: "money",
total: true,
},
] | readonly DataColumn<R>[] | — |
| rows* จำเป็น | รายการ 3 รายการ[
{
key: "1",
description: "คอมพิวเตอร์โน้ตบุ๊ก",
quantity: 5,
unit: "เครื่อง",
unitPrice: 27000,
amount: 135000,
},
{
key: "2",
description: "กระเป๋าใส่โน้ตบุ๊ก",
quantity: 5,
unit: "ใบ",
unitPrice: 1000,
amount: 5000,
},
{
key: "3",
description: "ติดตั้งและตั้งค่าซอฟต์แวร์",
quantity: 1,
unit: "งาน",
unitPrice: 10000,
amount: 10000,
},
] | readonly R[] | All rows. With total set, only the rows of the current page. |
| rowKey* จำเป็น | "key" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| paged | false | boolean | false shows every row, with no range text, page size or pager, for a short list that belongs to one record, such as the lines of a purchase request. true by default. Ignored with total. |
| totals | { amount: 150000 } | Readonly<Partial<Record<keyof R & string, number>>> | Totals from the core API, by column key, shown in the total row. Pass them for a list the core API pages, and for a record's lines, so the total matches the record's amount. A total column without one here is added up from the rows, except in a list the core API pages. |
| totalLabel | "รวมทั้งสิ้น" | string | Labels the total row. รวมทุกหน้า by default, or รวม with paged false. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
กำลังโหลด
status loading แสดงแถวโครงร่างตามคอลัมน์จริง และซ่อนตัวแบ่งหน้าและยอดรวม
กำลังโหลด
const columns: DataColumn<Request>[] = [
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
];
<DataTable
caption="คำขอซื้อขอจ้าง"
columns={columns}
rows={rows}
rowKey="no"
search={{ placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย" }}
status="loading"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "คำขอซื้อขอจ้าง" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 6 รายการ[
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
] | readonly DataColumn<R>[] | — |
| rows* จำเป็น | [] | readonly R[] | All rows. With total set, only the rows of the current page. |
| rowKey* จำเป็น | "no" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| search | { placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย" } | TableSearch | false | The search box. Without total, the table searches the searchable columns itself, and shows the box even when this is left out, with ค้นหา (Search) as its placeholder. With total the core API pages the list, so pass a search with onChange to get a box. false hides it. A table with paged false shows one only when this is passed. |
| status | "loading" | "ready" | "loading" | "error" ค่าที่ใช้ได้: "ready""loading""error" | loading shows placeholder rows, error shows the error. ready by default. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
โหลดไม่สำเร็จ
status error แสดงสิ่งที่เกิดขึ้น สิ่งที่ควรทำ และรหัสอ้างอิงสำหรับผู้ดูแลระบบ onRetry เพิ่มปุ่มลองอีกครั้ง
โหลดรายการไม่สำเร็จ
โหลดรายการไม่สำเร็จ ลองอีกครั้ง ถ้ายังไม่สำเร็จ แจ้งผู้ดูแลระบบพร้อมรหัสอ้างอิง รหัสอ้างอิง | |||||
const columns: DataColumn<Request>[] = [
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
];
<DataTable
caption="คำขอซื้อขอจ้าง"
columns={columns}
rows={rows}
rowKey="no"
status="error"
error={{
title: "โหลดรายการไม่สำเร็จ",
body: "ลองอีกครั้ง ถ้ายังไม่สำเร็จ แจ้งผู้ดูแลระบบพร้อมรหัสอ้างอิง",
correlationId: "c0ffee00-0000-4000-8000-000000000001",
onRetry: reload,
}}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "คำขอซื้อขอจ้าง" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 6 รายการ[
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
] | readonly DataColumn<R>[] | — |
| rows* จำเป็น | [] | readonly R[] | All rows. With total set, only the rows of the current page. |
| rowKey* จำเป็น | "no" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| status | "error" | "ready" | "loading" | "error" ค่าที่ใช้ได้: "ready""loading""error" | loading shows placeholder rows, error shows the error. ready by default. |
| error | ออบเจกต์ 4 ฟิลด์{
title: "โหลดรายการไม่สำเร็จ",
body: "ลองอีกครั้ง ถ้ายังไม่สำเร็จ แจ้งผู้ดูแลระบบพร้อมรหัสอ้างอิง",
correlationId: "c0ffee00-0000-4000-8000-000000000001",
onRetry: () => {},
} | TableError | What to say when status is error. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
ชื่อคนที่เปิดรายการ
คอลัมน์ที่มีทั้ง avatar และ opens: เฉพาะชื่อเป็นลิงก์ ชิดซ้าย ไทล์ชื่อย่อและบรรทัด sub ไม่ขีดเส้นใต้ ตารางนี้ไม่ได้ส่ง search จึงแสดงช่องค้นหาของตารางเอง ที่มีคำว่า ค้นหา
พบ 3 คน
| จัดการ | |||
|---|---|---|---|
| test.sample@example.ac.th | สำนักงานอธิการบดี | ใช้งาน | |
| sommut.j@example.ac.th | คณะวิทยาศาสตร์ | ใช้งาน | |
| bessie.c@example.ac.th | กองคลัง | ถูกล็อก |
const columns: DataColumn<Person>[] = [
{
key: "name",
label: "ชื่อ",
sub: "email",
avatar: true,
opens: true,
sortable: true,
},
{ key: "unit", label: "หน่วยงาน", sortable: true },
{
key: "status",
label: "สถานะ",
kind: "badge",
badges: {
active: { tone: "approved", icon: Check, label: "ใช้งาน" },
locked: { tone: "rejected", icon: X, label: "ถูกล็อก" },
},
},
];
<DataTable
caption="ผู้ใช้"
columns={columns}
rows={users}
rowKey="id"
onOpen={setOpened}
noun="คน"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "ผู้ใช้" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 3 รายการ[
{
key: "name",
label: "ชื่อ",
sub: "email",
avatar: true,
opens: true,
sortable: true,
},
{ key: "unit", label: "หน่วยงาน", sortable: true },
{
key: "status",
label: "สถานะ",
kind: "badge",
badges: {
active: { tone: "approved", icon: Check, label: "ใช้งาน" },
locked: { tone: "rejected", icon: X, label: "ถูกล็อก" },
},
},
] | readonly DataColumn<R>[] | — |
| rows* จำเป็น | รายการ 3 รายการ[
{
id: "u-001",
name: "นายทดสอบ ตัวอย่าง",
email: "test.sample@example.ac.th",
unit: "สำนักงานอธิการบดี",
status: "active",
},
{
id: "u-002",
name: "นางสาวสมมุติ ใจดี",
email: "sommut.j@example.ac.th",
unit: "คณะวิทยาศาสตร์",
status: "active",
},
{
id: "u-003",
name: "Bessie Cooper",
email: "bessie.c@example.ac.th",
unit: "กองคลัง",
status: "locked",
},
] | readonly R[] | All rows. With total set, only the rows of the current page. |
| rowKey* จำเป็น | "id" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| noun | "คน" | string | The record name in the result count, such as รายการ or คำขอ. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | setOpened | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
ยังไม่มีข้อมูล
เมื่อไม่มีแถวเลยและไม่มีการค้นหาหรือตัวกรอง empty แทนที่ทั้งตาราง ส่ง action เฉพาะผู้ที่มีสิทธิ์สร้างรายการ
ยังไม่มีคำขอซื้อขอจ้าง
คำขอที่คุณสร้างหรือที่รอคุณอนุมัติจะแสดงที่นี่
const columns: DataColumn<Request>[] = [
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
];
<DataTable
caption="คำขอซื้อขอจ้าง"
columns={columns}
rows={rows}
rowKey="no"
empty={{
title: "ยังไม่มีคำขอซื้อขอจ้าง",
body: "คำขอที่คุณสร้างหรือที่รอคุณอนุมัติจะแสดงที่นี่",
icon: ClipboardList,
action: {
label: "สร้างคำขอ",
icon: Plus,
tone: "primary",
onClick: createRequest,
},
}}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "คำขอซื้อขอจ้าง" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 6 รายการ[
{ key: "no", label: "เลขที่", sortable: true, opens: true },
{ key: "item", label: "รายการ", sortable: true },
{
key: "vendor",
label: "ผู้ขาย",
sub: "vendorCode",
avatar: true,
hideOnPhone: true,
},
{ key: "date", label: "วันที่", kind: "date", sortable: true },
{
key: "amount",
label: "วงเงิน (บาท)",
kind: "money",
sortable: true,
total: true,
},
{
key: "status",
label: "สถานะ",
kind: "badge",
sortable: true,
badges: {
draft: { tone: "draft", label: "ร่าง", icon: Pencil },
pending: { tone: "pending", label: "รออนุมัติ", icon: Clock },
approved: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
rejected: { tone: "rejected", label: "ไม่อนุมัติ", icon: X },
},
},
] | readonly DataColumn<R>[] | — |
| rows* จำเป็น | [] | readonly R[] | All rows. With total set, only the rows of the current page. |
| rowKey* จำเป็น | "no" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| empty | ออบเจกต์ 4 ฟิลด์{
title: "ยังไม่มีคำขอซื้อขอจ้าง",
body: "คำขอที่คุณสร้างหรือที่รอคุณอนุมัติจะแสดงที่นี่",
icon: ClipboardList,
action: { label: "สร้างคำขอ", icon: Plus, tone: "primary", onClick: () => {} },
} | TableEmpty | What to show when there are no records at all, and nobody is searching or filtering. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | string | — | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | readonly DataColumn<R>[] | — | — |
| rows* จำเป็น | readonly R[] | — | All rows. With total set, only the rows of the current page. |
| rowKey* จำเป็น | keyof R & string | — | The field that identifies a row, such as no. Selection and onOpen use its value. |
| search | TableSearch | false | — | The search box. Without total, the table searches the searchable columns itself, and shows the box even when this is left out, with ค้นหา (Search) as its placeholder. With total the core API pages the list, so pass a search with onChange to get a box. false hides it. A table with paged false shows one only when this is passed. |
| filters | TableFilters | — | The filters in the filter bar, on the left of the search box, and their chips under it. The screen filters the rows. |
| sort | TableSort | — | The sort in use, when the screen keeps it. |
| defaultSort | TableSort | — | The sort on first render, when the table keeps it. |
| onSortChange | (next: TableSort) => void | — | Hears every sort change. Go back to page 1. |
| page | number | — | The page shown, from 1, when the screen keeps it. |
| onPageChange | (next: number) => void | — | — |
| pageSize | number | — | Rows per page, when the screen keeps it. 10 by default. |
| onPageSizeChange | (next: number) => void | — | — |
| pageSizes | readonly number[] | PAGE_SIZES | The page sizes people can choose. |
| paged | boolean | true | false shows every row, with no range text, page size or pager, for a short list that belongs to one record, such as the lines of a purchase request. true by default. Ignored with total. |
| total | number | — | How many rows match on the server, for a list the core API pages. The table then shows rows as given. |
| totals | Readonly<Partial<Record<keyof R & string, number>>> | — | Totals from the core API, by column key, shown in the total row. Pass them for a list the core API pages, and for a record's lines, so the total matches the record's amount. A total column without one here is added up from the rows, except in a list the core API pages. |
| totalLabel | string | — | Labels the total row. รวมทุกหน้า by default, or รวม with paged false. |
| selection | TableSelection | — | Adds a checkbox to each row, and a bar of actions while any row is chosen. |
| onOpen | (row: R) => void | — | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | (row: R) => string | — | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | (row: R) => string | — | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
| status | "ready" | "loading" | "error" | "ready" | loading shows placeholder rows, error shows the error. ready by default. |
| error | TableError | — | What to say when status is error. |
| empty | TableEmpty | — | What to show when there are no records at all, and nobody is searching or filtering. |
| noun | string | — | The record name in the result count, such as รายการ or คำขอ. |
ชนิดข้อมูล
DataColumn
One column of a DataTable. The table reads the value from each row by key, and formats it by kind.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| key* จำเป็น | keyof R & string | — | The row field to show. It also names the column when sorting, and in a server query. |
| label* จำเป็น | string | — | The heading, already in the screen language. At phone width it labels the value in each row. |
| kind | ColumnKind ค่าที่ใช้ได้: "text""number""money""date""badge" | — | text by default. A text value may be a string or a Text pair. number and money take numbers, and money shows two decimals. date takes an ISO date such as 2026-11-02. badge looks the value up in badges. |
| sortable | boolean | — | People can sort by this column. In a table that has every row and pages them, every column sorts unless this is false. With total the core API sorts, so only columns with true sort, and the screen handles onSortChange. With paged false, a record's lines keep their order unless this is true. |
| searchable | boolean | — | The search box looks in this column. Text columns are searched unless this is false. |
| badges | Readonly<Record<string, BadgeStyle>> | — | For a badge column: how each value shows, such as { pending: { tone: "pending", label: "รออนุมัติ" } }. |
| sub | keyof R & string | — | Another row field, shown as a smaller second line, such as a vendor code under the vendor name. |
| avatar | boolean | — | Shows the value's initials in a round tile before it, such as for a person's or a unit's name. |
| opens | boolean | — | The value opens the row, through the table's onOpen or openHref. Usually the record number. |
| total | boolean | — | Adds the column up in the total row. For number and money columns. |
| unit | keyof R & string | — | Another row field, shown after a number or money value, such as เครื่อง after a quantity of 5. The value keeps its own formatting and alignment, and sorting and the total use the number alone. |
| hideOnPhone | boolean | — | Hides the column at phone width, where each row becomes a block. |
Text
A string in both languages. Thai comes first because it is the default.
type Text = readonly [th: string, en: string];ColumnKind
How a column shows its value.
type ColumnKind = "text" | "number" | "money" | "date" | "badge";BadgeStyle
How a badge column shows one value, such as pending.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| tone* จำเป็น | BadgeTone ค่าที่ใช้ได้: "draft""pending""approved""paid""request""rejected""line" | — | — |
| label* จำเป็น | string | — | The badge text, already in the screen language. |
| icon | LucideIcon | — | — |
BadgeTone
The state a badge reports. Each one has its own colour. line is for facts that aren't a state.
type BadgeTone = "draft" | "pending" | "approved" | "paid" | "request" | "rejected" | "line";TableSearch
The search box above the table.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| placeholder* จำเป็น | string | — | Says what can be searched, such as ค้นหาเลขที่หรือรายการ. It is also the box's accessible name. |
| value | string | — | The search text, when the screen keeps it. |
| onChange | (q: string) => void | — | Hears the search text. With total set, it comes after a short pause, ready for a query to the core API. |
TableFilters
The filters in the filter bar above the table, and a chip for each one in use.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| chips* จำเป็น | readonly FilterChip[] | — | The filters in use, one chip each. Removing one should go back to page 1. |
| onClearAll* จำเป็น | () => void | — | Called by Clear all. Remove every filter, including those without a chip, such as putting a Segmented back on its All choice, but keep the search text. |
| active | boolean | — | The filters on the bar are narrowing the list, even where a filter has no chip, such as a Segmented that isn't on its All choice. With no rows, the table then says nothing matches the filters, keeps the bar and offers Clear all, instead of showing empty as if nothing existed yet. True whenever chips has any. |
| panel | ReactNode | — | The filters, built from the library's fields, shown in one row on the left of the filter bar, with the search box on the right. Use compact fields: a Select, Combobox or DateInput with hideLabel and a placeholder that names the filter, and a Segmented with a count on each choice. |
FilterChip
One filter in use, shown as a chip.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| key* จำเป็น | string | — | Unique among the chips, such as status-pending. |
| label* จำเป็น | string | — | What the filter is, already in the screen language and formatted, such as a date range. |
| onRemove* จำเป็น | () => void | — | Called when the chip's remove button is pressed. Remove the filter and go back to page 1. |
TableSort
The column a table is sorted by, and which way.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| key* จำเป็น | string | — | — |
| dir* จำเป็น | SortDir ค่าที่ใช้ได้: "asc""desc" | — | — |
SortDir
The sort direction: asc for A to Z and smallest first, desc for the reverse.
type SortDir = "asc" | "desc";TableSelection
Row selection, with actions on the chosen rows.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| selected | readonly string[] | — | The chosen rows' keys, when the screen keeps them. |
| onChange | (keys: string[]) => void | — | Hears the chosen keys after every change. |
| actions* จำเป็น | readonly BulkAction[] | — | The actions on the chosen rows, such as Export. |
BulkAction
An action on the chosen rows, shown in the bar above the table while any row is chosen.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| label* จำเป็น | string | — | The button text, already in the screen language. |
| icon | LucideIcon | — | — |
| tone | "primary" | "secondary" | "danger" | — | secondary by default. |
| onRun* จำเป็น | (keys: string[]) => void | — | Gets the keys of every chosen row, across all pages. |
TableError
What the table shows instead of rows when they failed to load.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| title* จำเป็น | string | — | What happened, in a short sentence. |
| body* จำเป็น | string | — | What to do next. |
| correlationId | string | — | The Correlation ID of the failed request, so support can trace it. |
| onRetry | () => void | — | Called by Try again. Leave out when trying again can't help. |
TableEmpty
What the table shows when nothing exists yet, before anyone has created a record.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| title* จำเป็น | string | — | Says there are no records yet, such as ยังไม่มีคำขอซื้อขอจ้าง. |
| body* จำเป็น | string | — | Says what will appear here, and how it gets here. |
| icon | LucideIcon | — | A Lucide icon for the kind of record. |
| action | TableAction | — | The button that creates the first record. Leave out for people who may not create one. |
TableAction
A button the table shows, such as Try again or Create request.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| label* จำเป็น | string | — | The button text, already in the screen language. |
| icon | LucideIcon | — | — |
| tone | "primary" | "secondary" | "danger" | — | secondary by default. Use primary for the one main action, and danger for one that deletes. |
| onClick* จำเป็น | () => void | — | — |
ข้อควรปฏิบัติ
- ห้ามวาง DataTable บนพื้นหน้าของ AppShell (shell-page) โดยตรง ให้อยู่ใน Card และอยู่ใน DashedContainer ภายในการ์ดเสมอ เช่น <Card title="คำขอซื้อขอจ้าง" description="คำขอของหน่วยงานในปีงบประมาณนี้" icon={ClipboardList}><DashedContainer><DataTable … /></DashedContainer></Card>
- รายการทุกตารางเรียงลำดับและแบ่งหน้าได้ เมื่อส่งทุกแถว ทุกคอลัมน์ที่มีหัวคอลัมน์เรียงได้เอง ยกเว้นคอลัมน์ที่บอก sortable: false และตารางแบ่งหน้าเองโดยแสดงช่วงรายการ จำนวนต่อหน้า และเลขหน้าเสมอ เมื่อ API ของ core แบ่งหน้า (มี total) ตารางเรียงและแบ่งหน้าเองไม่ได้ ให้บอก sortable: true ที่คอลัมน์ที่ API เรียงได้ ส่ง sort หรือ defaultSort กับ onSortChange และ page กับ onPageChange แล้วดึงข้อมูลใหม่ paged={false} ใช้เฉพาะรายการของเอกสาร ซึ่งคงลำดับเดิมไว้
- รายการทุกตารางมีช่องค้นหา เมื่อส่งทุกแถว ตารางแสดงช่องค้นหาเองแม้ไม่ส่ง search โดยมีคำว่า ค้นหา ส่ง search เพื่อบอกว่าค้นหาอะไรได้ เช่น ค้นหาเลขที่หรือรายการ เมื่อ API ของ core แบ่งหน้า (มี total) ตารางค้นหาเองไม่ได้ หน้าจอต้องส่ง search ที่มี onChange แล้วดึงข้อมูลใหม่ search={false} ซ่อนช่องค้นหา ใช้เฉพาะตารางรายการของเอกสาร (paged={false}) ซึ่งไม่มีช่องค้นหาอยู่แล้วถ้าไม่ส่ง search
- ตัวกรองของรายการอยู่บนแถบตัวกรองเหนือตารางเสมอ ส่งผ่าน filters.panel เรียงจากซ้าย ไม่มีปุ่มเงื่อนไขค้นหาให้กดก่อน ช่องค้นหาอยู่ทางขวา กว้างราวหนึ่งในห้าของตาราง ใช้ช่องแบบกะทัดรัด: Segmented ที่มี count และ Select, Combobox หรือ DateInput ที่ใส่ hideLabel พร้อม label และ placeholder ที่บอกชื่อตัวกรอง ไม่วางแบบฟอร์มหลายแถวหรือปุ่มใช้ตัวกรองบนแถบ
- ส่ง filters.active เป็น true เมื่อมีตัวกรองบนแถบที่ไม่มีชิปกำลังกรองรายการ เช่น Segmented ที่ไม่ได้อยู่ที่ ทั้งหมด เพื่อให้รายการที่กรองแล้วว่างแสดงว่าไม่พบรายการที่ตรงกับเงื่อนไข ไม่ใช่หน้าว่างของรายการที่ยังไม่มีข้อมูล onClearAll ต้องล้างตัวกรองทุกตัวบนแถบ รวมถึงตั้ง Segmented กลับไปที่ ทั้งหมด
- ข้อความทั้งหมด เช่น หัวคอลัมน์และป้ายสถานะ ส่งมาในภาษาของหน้าจอ ค่าแบบข้อความอาจเป็นคู่ Text [ไทย, อังกฤษ] ได้
- rowKey ต้องไม่ซ้ำกันในทุกแถว เพราะการเลือกและการเปิดรายการใช้ค่านี้
- เงินคำนวณที่เซิร์ฟเวอร์เสมอ ตารางแสดงผลเท่านั้น ยอดรวมของรายการที่แบ่งหน้าต้องมาจาก API ผ่าน totals
- เมื่อเปลี่ยนการค้นหา การเรียง ตัวกรอง หรือจำนวนต่อหน้า ให้กลับไปหน้า 1 ตารางทำเองเมื่อเก็บสถานะเอง
- ในคอลัมน์ที่มี opens เฉพาะค่าเท่านั้นที่เป็นลิงก์ ชิดซ้ายเหมือนค่าอื่นในคอลัมน์ ไทล์ชื่อย่อของ avatar และบรรทัด sub อยู่นอกลิงก์ ไม่ขีดเส้นใต้
- บนหน้าจอโทรศัพท์ แต่ละแถวเป็นบล็อกที่มีป้ายชื่อตามหัวคอลัมน์ คอลัมน์รองใช้ hideOnPhone
ซอร์สโค้ด: ui/src/table.tsx