ข้ามไปยังเนื้อหา

ตารางข้อมูล

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-000211 พ.ย. 256943,400.00รออนุมัติ
PR-2570-0022ค่าเช่าซอฟต์แวร์บริษัท ทดสอบ จำกัดV-00018 ต.ค. 256969,250.00ไม่อนุมัติ
PR-2570-0021หมึกพิมพ์ร้าน ตัวอย่างการค้าV-00035 ธ.ค. 256917,750.00ร่าง
PR-2570-0020โต๊ะและเก้าอี้ห้องเรียนห้างหุ้นส่วน สมมติV-00022 พ.ย. 256990,750.00อนุมัติแล้ว
PR-2570-0019จ้างซ่อมเครื่องปรับอากาศบริษัท ทดสอบ จำกัดV-000127 ต.ค. 256946,500.00รออนุมัติ
PR-2570-0018วัสดุสำนักงานร้าน ตัวอย่างการค้าV-000324 ธ.ค. 256922,750.00อนุมัติแล้ว
PR-2570-0017ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่องห้างหุ้นส่วน สมมติV-000221 พ.ย. 2569154,000.00รออนุมัติ
PR-2570-0016จ้างทำความสะอาดบริษัท ทดสอบ จำกัดV-000118 ต.ค. 256998,750.00ไม่อนุมัติ
PR-2570-0015เครื่องฉายภาพร้าน ตัวอย่างการค้าV-000315 ธ.ค. 256941,400.00ร่าง
PR-2570-0014ค่าเช่าซอฟต์แวร์ห้างหุ้นส่วน สมมติV-000212 พ.ย. 256967,250.00อนุมัติแล้ว
รวมทุกหน้า1,486,700.00
แสดง 1-10 จาก 23 คำขอต่อหน้า
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="คำขอ"
/>

เลือกหลายแถวและเปิดรายการ

selection เพิ่มช่องเลือกในทุกแถวและแถบคำสั่งเมื่อมีแถวที่เลือก onRun ได้รับรหัสของทุกแถวที่เลือก onOpen ทำให้ค่าในคอลัมน์ที่มี opens กดได้ และเพิ่มปุ่มดูรายละเอียด ได้รับแถวนั้น หน้าจอเก็บแถวไว้ใน state แล้วแสดงใน Drawer ลองกดเลขที่หรือปุ่มดูรายละเอียด ใช้ openHref แทนเมื่อเปิดเป็นหน้าใหม่

พบ 23 คำขอ

คำขอซื้อขอจ้าง
จัดการ
ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่องบริษัท ทดสอบ จำกัดV-00011 ต.ค. 2569150,000.00รออนุมัติ
วัสดุสำนักงานห้างหุ้นส่วน สมมติV-00024 พ.ย. 256918,750.00อนุมัติแล้ว
จ้างซ่อมเครื่องปรับอากาศร้าน ตัวอย่างการค้าV-00037 ธ.ค. 256942,500.00ร่าง
โต๊ะและเก้าอี้ห้องเรียนบริษัท ทดสอบ จำกัดV-000110 ต.ค. 256986,750.00ไม่อนุมัติ
หมึกพิมพ์ห้างหุ้นส่วน สมมติV-000213 พ.ย. 256913,750.00รออนุมัติ
ค่าเช่าซอฟต์แวร์ร้าน ตัวอย่างการค้าV-000316 ธ.ค. 256965,250.00อนุมัติแล้ว
เครื่องฉายภาพบริษัท ทดสอบ จำกัดV-000119 ต.ค. 256939,400.00รออนุมัติ
จ้างทำความสะอาดห้างหุ้นส่วน สมมติV-000222 พ.ย. 256996,750.00อนุมัติแล้ว
ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่องร้าน ตัวอย่างการค้าV-000325 ธ.ค. 2569152,000.00ร่าง
วัสดุสำนักงานบริษัท ทดสอบ จำกัดV-000128 ต.ค. 256920,750.00ไม่อนุมัติ
รวมทุกหน้า1,486,700.00
แสดง 1-10 จาก 23 คำขอต่อหน้า
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>

แถบตัวกรองและชิปตัวกรอง

ตัวกรองอยู่บนแถบเหนือตารางเสมอ เรียงจากซ้าย ช่องค้นหาอยู่ทางขวา กว้างราวหนึ่งในห้าของตาราง ไม่มีปุ่มให้กดเปิดก่อน ใช้ช่องแบบกะทัดรัด: Segmented ที่มีจำนวนในแต่ละตัวเลือก และ Select, Combobox หรือ DateInput ที่ใส่ hideLabel พร้อม placeholder ที่บอกชื่อตัวกรอง หน้าจอเก็บตัวกรองไว้เอง กรองแถว แล้วส่งชิปของตัวกรองที่ใช้อยู่

พบ 8 คำขอ

หน่วยงาน

หน่วยงาน ก
คำขอซื้อขอจ้าง
PR-2570-0001ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่องบริษัท ทดสอบ จำกัดV-00011 ต.ค. 2569150,000.00รออนุมัติ
PR-2570-0004โต๊ะและเก้าอี้ห้องเรียนบริษัท ทดสอบ จำกัดV-000110 ต.ค. 256986,750.00ไม่อนุมัติ
PR-2570-0007เครื่องฉายภาพบริษัท ทดสอบ จำกัดV-000119 ต.ค. 256939,400.00รออนุมัติ
PR-2570-0010วัสดุสำนักงานบริษัท ทดสอบ จำกัดV-000128 ต.ค. 256920,750.00ไม่อนุมัติ
PR-2570-0013หมึกพิมพ์บริษัท ทดสอบ จำกัดV-00019 ต.ค. 256915,750.00รออนุมัติ
PR-2570-0016จ้างทำความสะอาดบริษัท ทดสอบ จำกัดV-000118 ต.ค. 256998,750.00ไม่อนุมัติ
PR-2570-0019จ้างซ่อมเครื่องปรับอากาศบริษัท ทดสอบ จำกัดV-000127 ต.ค. 256946,500.00รออนุมัติ
PR-2570-0022ค่าเช่าซอฟต์แวร์บริษัท ทดสอบ จำกัดV-00018 ต.ค. 256969,250.00ไม่อนุมัติ
รวมทุกหน้า527,150.00
แสดง 1-8 จาก 8 คำขอต่อหน้า
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="คำขอ"
/>

ตัวกรองที่ไม่พบรายการ

ตัวกรองที่ไม่มีชิป เช่น 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="คำขอ"
/>

รายการที่ 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="คำขอ"
/>

รายการของเอกสารหนึ่งฉบับ

รายการสินค้าหรือบริการของคำขอหนึ่งฉบับ เช่น ในแท็บรายการหรือ RecordSection paged={false} แสดงทุกแถวโดยไม่มีข้อความช่วงรายการ ขนาดหน้า หรือตัวแบ่งหน้า unit แสดงหน่วยต่อจากจำนวน และ totals ส่งยอดรวมจาก core API ให้ตรงกับยอดของคำขอ

พบ 3 รายการ

รายการในคำขอ PR-2570-0001
รายการจำนวนราคาต่อหน่วยจำนวนเงิน (บาท)
คอมพิวเตอร์โน้ตบุ๊ก5 เครื่อง27,000.00135,000.00
กระเป๋าใส่โน้ตบุ๊ก5 ใบ1,000.005,000.00
ติดตั้งและตั้งค่าซอฟต์แวร์1 งาน10,000.0010,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="รวมทั้งสิ้น"
/>

กำลังโหลด

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"
/>

โหลดไม่สำเร็จ

status error แสดงสิ่งที่เกิดขึ้น สิ่งที่ควรทำ และรหัสอ้างอิงสำหรับผู้ดูแลระบบ onRetry เพิ่มปุ่มลองอีกครั้ง

โหลดรายการไม่สำเร็จ

คำขอซื้อขอจ้าง

โหลดรายการไม่สำเร็จ

ลองอีกครั้ง ถ้ายังไม่สำเร็จ แจ้งผู้ดูแลระบบพร้อมรหัสอ้างอิง

รหัสอ้างอิง c0ffee00-0000-4000-8000-000000000001

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,
  }}
/>

ชื่อคนที่เปิดรายการ

คอลัมน์ที่มีทั้ง avatar และ opens: เฉพาะชื่อเป็นลิงก์ ชิดซ้าย ไทล์ชื่อย่อและบรรทัด sub ไม่ขีดเส้นใต้ ตารางนี้ไม่ได้ส่ง search จึงแสดงช่องค้นหาของตารางเอง ที่มีคำว่า ค้นหา

พบ 3 คน

ผู้ใช้
จัดการ
test.sample@example.ac.thสำนักงานอธิการบดีใช้งาน
sommut.j@example.ac.thคณะวิทยาศาสตร์ใช้งาน
bessie.c@example.ac.thกองคลังถูกล็อก
แสดง 1-3 จาก 3 คนต่อหน้า
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="คน"
/>

ยังไม่มีข้อมูล

เมื่อไม่มีแถวเลยและไม่มีการค้นหาหรือตัวกรอง 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,
    },
  }}
/>

props ทั้งหมด

ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้

DataTable 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.
filtersTableFilters—The filters in the filter bar, on the left of the search box, and their chips under it. The screen filters the rows.
sortTableSort—The sort in use, when the screen keeps it.
defaultSortTableSort—The sort on first render, when the table keeps it.
onSortChange(next: TableSort) => void—Hears every sort change. Go back to page 1.
pagenumber—The page shown, from 1, when the screen keeps it.
onPageChange(next: number) => void——
pageSizenumber—Rows per page, when the screen keeps it. 10 by default.
onPageSizeChange(next: number) => void——
pageSizesreadonly number[]PAGE_SIZESThe page sizes people can choose.
pagedbooleantruefalse 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.
totalnumber—How many rows match on the server, for a list the core API pages. The table then shows rows as given.
totalsReadonly<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.
totalLabelstring—Labels the total row. รวมทุกหน้า by default, or รวม with paged false.
selectionTableSelection—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.
errorTableError—What to say when status is error.
emptyTableEmpty—What to show when there are no records at all, and nobody is searching or filtering.
nounstring—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.

DataColumn fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
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.
kindColumnKind
ค่าที่ใช้ได้:"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.
sortableboolean—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.
searchableboolean—The search box looks in this column. Text columns are searched unless this is false.
badgesReadonly<Record<string, BadgeStyle>>—For a badge column: how each value shows, such as { pending: { tone: "pending", label: "รออนุมัติ" } }.
subkeyof R & string—Another row field, shown as a smaller second line, such as a vendor code under the vendor name.
avatarboolean—Shows the value's initials in a round tile before it, such as for a person's or a unit's name.
opensboolean—The value opens the row, through the table's onOpen or openHref. Usually the record number.
totalboolean—Adds the column up in the total row. For number and money columns.
unitkeyof 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.
hideOnPhoneboolean—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.

BadgeStyle fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
tone* จำเป็นBadgeTone
ค่าที่ใช้ได้:"draft""pending""approved""paid""request""rejected""line"
——
label* จำเป็นstring—The badge text, already in the screen language.
iconLucideIcon——

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.

TableSearch fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
placeholder* จำเป็นstring—Says what can be searched, such as ค้นหาเลขที่หรือรายการ. It is also the box's accessible name.
valuestring—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.

TableFilters fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
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.
activeboolean—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.
panelReactNode—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.

FilterChip fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
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.

TableSort fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
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.

TableSelection fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
selectedreadonly 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.

BulkAction fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
label* จำเป็นstring—The button text, already in the screen language.
iconLucideIcon——
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.

TableError fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
title* จำเป็นstring—What happened, in a short sentence.
body* จำเป็นstring—What to do next.
correlationIdstring—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.

TableEmpty fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
title* จำเป็นstring—Says there are no records yet, such as ยังไม่มีคำขอซื้อขอจ้าง.
body* จำเป็นstring—Says what will appear here, and how it gets here.
iconLucideIcon—A Lucide icon for the kind of record.
actionTableAction—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.

TableAction fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
label* จำเป็นstring—The button text, already in the screen language.
iconLucideIcon——
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