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

ตารางข้อมูล

DataTable

A complete data table from columns and rows: search, criteria and 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.

ใช้แสดงรายการข้อมูลทุกแบบ หน้าจอส่งคอลัมน์และแถวเป็นข้อมูล แล้วตารางจัดการค้นหา เรียงลำดับ แบ่งหน้า เลือกหลายแถว แถวรวม และสถานะต่าง ๆ เอง หน้าจอไม่ต้องเขียน <table> หรือคลาสของแนวทางการออกแบบ ถ้าทุกแถวอยู่ในหน้าจอแล้ว ส่ง 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-10 จาก 23 คำขอต่อหน้า
const columns: DataColumn<Request>[] = [
  { key: "no", label: "เลขที่", sortable: true, opens: true },
  { key: "item", label: "รายการ", sortable: true },
  {
    key: "vendor",
    label: "ผู้ขาย",
    sub: "vendorCode",
    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-10 จาก 23 คำขอต่อหน้า
const columns: DataColumn<Request>[] = [
  { key: "no", label: "เลขที่", sortable: true, opens: true },
  { key: "item", label: "รายการ", sortable: true },
  {
    key: "vendor",
    label: "ผู้ขาย",
    sub: "vendorCode",
    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>

เงื่อนไขค้นหาและชิปตัวกรอง

หน้าจอเก็บตัวกรองไว้เอง กรองแถว แล้วส่งชิปของตัวกรองที่ใช้อยู่ panel คือแบบฟอร์มเงื่อนไขที่สร้างจากคอมโพเนนต์ของไลบรารี แสดงใต้ปุ่มเงื่อนไขค้นหา

พบ 8 คำขอ

รออนุมัติ
คำขอซื้อขอจ้าง
ผู้ขาย
PR-2570-0001ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่องบริษัท ทดสอบ จำกัดV-00011 ต.ค. 2569150,000.00รออนุมัติ
PR-2570-0005หมึกพิมพ์ห้างหุ้นส่วน สมมติV-000213 พ.ย. 256913,750.00รออนุมัติ
PR-2570-0007เครื่องฉายภาพบริษัท ทดสอบ จำกัดV-000119 ต.ค. 256939,400.00รออนุมัติ
PR-2570-0011จ้างซ่อมเครื่องปรับอากาศห้างหุ้นส่วน สมมติV-00023 พ.ย. 256944,500.00รออนุมัติ
PR-2570-0013หมึกพิมพ์บริษัท ทดสอบ จำกัดV-00019 ต.ค. 256915,750.00รออนุมัติ
PR-2570-0017ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่องห้างหุ้นส่วน สมมติV-000221 พ.ย. 2569154,000.00รออนุมัติ
PR-2570-0019จ้างซ่อมเครื่องปรับอากาศบริษัท ทดสอบ จำกัดV-000127 ต.ค. 256946,500.00รออนุมัติ
PR-2570-0023เครื่องฉายภาพห้างหุ้นส่วน สมมติV-000211 พ.ย. 256943,400.00รออนุมัติ
แสดง 1-8 จาก 8 คำขอต่อหน้า
const [statuses, setStatuses] = useState<string[]>(["pending"]);
const shown = statuses.length ? rows.filter((r) => statuses.includes(r.status)) : rows;
const chips: FilterChip[] = statuses.map((s) => ({
  key: s,
  label: statusLabel(s),
  onRemove: () => setStatuses(statuses.filter((v) => v !== s)),
}));

<DataTable
  caption="คำขอซื้อขอจ้าง"
  columns={columns}
  rows={shown}
  rowKey="no"
  search={{ placeholder: "ค้นหาเลขที่ รายการ หรือผู้ขาย" }}
  filters={{
    chips,
    onClearAll: () => setStatuses([]),
    panel: (
      <Select multiple label="สถานะ" placeholder="ทุกสถานะ"
        options={statusOptions} value={statuses} onChange={setStatuses} />
    ),
  }}
  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="คำขอ"
/>

กำลังโหลด

status loading แสดงแถวโครงร่างตามคอลัมน์จริง และซ่อนตัวแบ่งหน้าและยอดรวม

กำลังโหลด

คำขอซื้อขอจ้าง
ผู้ขาย
const columns: DataColumn<Request>[] = [
  { key: "no", label: "เลขที่", sortable: true, opens: true },
  { key: "item", label: "รายการ", sortable: true },
  {
    key: "vendor",
    label: "ผู้ขาย",
    sub: "vendorCode",
    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",
    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,
  }}
/>

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

เมื่อไม่มีแถวเลยและไม่มีการค้นหาหรือตัวกรอง empty แทนที่ทั้งตาราง ส่ง action เฉพาะผู้ที่มีสิทธิ์สร้างรายการ

ยังไม่มีคำขอซื้อขอจ้าง

คำขอที่คุณสร้างหรือที่รอคุณอนุมัติจะแสดงที่นี่

const columns: DataColumn<Request>[] = [
  { key: "no", label: "เลขที่", sortable: true, opens: true },
  { key: "item", label: "รายการ", sortable: true },
  {
    key: "vendor",
    label: "ผู้ขาย",
    sub: "vendorCode",
    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—Shows filter chips, and a criteria panel when it has one. 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.
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 for a paged list, by column key. Without total, the table adds up total columns itself.
totalLabelstring—Labels the total row. รวมทุกหน้า by default.
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.
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.
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.
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 use, and the criteria panel that sets them.

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, but keep the search text.
panelReactNode—The criteria form, built from the library's fields, shown under a Search criteria button.

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——

ข้อควรปฏิบัติ

  • ข้อความทั้งหมด เช่น หัวคอลัมน์และป้ายสถานะ ส่งมาในภาษาของหน้าจอ ค่าแบบข้อความอาจเป็นคู่ Text [ไทย, อังกฤษ] ได้
  • rowKey ต้องไม่ซ้ำกันในทุกแถว เพราะการเลือกและการเปิดรายการใช้ค่านี้
  • เงินคำนวณที่เซิร์ฟเวอร์เสมอ ตารางแสดงผลเท่านั้น ยอดรวมของรายการที่แบ่งหน้าต้องมาจาก API ผ่าน totals
  • เมื่อเปลี่ยนการค้นหา การเรียง ตัวกรอง หรือจำนวนต่อหน้า ให้กลับไปหน้า 1 ตารางทำเองเมื่อเก็บสถานะเอง
  • บนหน้าจอโทรศัพท์ แต่ละแถวเป็นบล็อกที่มีป้ายชื่อตามหัวคอลัมน์ คอลัมน์รองใช้ hideOnPhone

ซอร์สโค้ด: ui/src/table.tsx