สถานะของตาราง
TableState
One row across all columns for a table that can't show rows: `no-results` when the search or filters match nothing, `error` when the rows failed to load. Say what happened, what to do next, and give the action. Keep the search box, criteria and chips on screen, and hide the pager and the total.
ใช้เป็นแถวเดียวเต็มความกว้างในเนื้อตาราง เมื่อตารางแสดงแถวไม่ได้: ไม่พบรายการที่ตรงกับคำค้นหาหรือตัวกรอง หรือโหลดไม่สำเร็จ ถ้ายังไม่มีข้อมูลเลยตั้งแต่แรก ใช้ TableFirstUse แทนทั้งตาราง ระหว่างโหลดใช้ TableSkeleton ตอนนี้หน้าจอยังต้องเขียนตาราง data-table และ tbody เอง
import { TableState } from "@bsru/ui";ตัวอย่าง
ไม่พบผลการค้นหา
บอกคำที่ค้นหาถ้ามี และให้ปุ่มล้างคำค้นหาและตัวกรองทั้งหมด colSpan เท่ากับจำนวนคอลัมน์
| เลขที่ | รายการ | หน่วยงาน | วงเงิน (บาท) | สถานะ |
|---|---|---|---|---|
ไม่พบรายการที่ตรงกับเงื่อนไข ไม่พบ "PR-9999" ลองคำอื่นหรือล้างเงื่อนไขบางข้อ | ||||
// Today the screen still writes the table. A data-driven DataTable is coming next.
<table className="data-table">
<thead>...</thead>
<tbody>
<TableState
kind="no-results"
colSpan={5}
title="ไม่พบรายการที่ตรงกับเงื่อนไข"
body={"ไม่พบ \"PR-9999\" ลองคำอื่นหรือล้างเงื่อนไขบางข้อ"}
action={<Component label="ล้างเงื่อนไขทั้งหมด" onClick={handleClick} />}
/>
</tbody>
</table>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| kind* จำเป็น | "no-results" | "no-results" | "error" ค่าที่ใช้ได้: "no-results""error" | no-results when nothing matches the search or filters, error when the rows failed to load. |
| colSpan* จำเป็น | 5 | number | The number of columns in the table, so the row spans all of them. |
| title* จำเป็น | "ไม่พบรายการที่ตรงกับเงื่อนไข" | string | What happened, in a short sentence. |
| body* จำเป็น | "ไม่พบ \"PR-9999\" ลองคำอื่นหรือล้างเงื่อนไขบางข้อ" | string | What to do next. |
| action | <Component label="ล้างเงื่อนไขทั้งหมด" onClick={handleClick} /> | ReactNode | The button, such as Clear all filters or Try again. |
โหลดไม่สำเร็จ
ข้อผิดพลาดที่ไม่คาดคิดต้องแสดงรหัสอ้างอิง (Correlation ID) จาก core API เพื่อให้ผู้ดูแลระบบตามได้ และมีปุ่มลองอีกครั้ง
| เลขที่ | รายการ | หน่วยงาน | วงเงิน (บาท) | สถานะ |
|---|---|---|---|---|
โหลดรายการไม่สำเร็จ ระบบไม่ตอบสนองในขณะนี้ ลองอีกครั้ง หากยังไม่ได้ แจ้งผู้ดูแลระบบพร้อมรหัสอ้างอิง รหัสอ้างอิง | ||||
// Today the screen still writes the table. A data-driven DataTable is coming next.
<table className="data-table">
<thead>...</thead>
<tbody>
<TableState
kind="error"
colSpan={5}
title="โหลดรายการไม่สำเร็จ"
body="ระบบไม่ตอบสนองในขณะนี้ ลองอีกครั้ง หากยังไม่ได้ แจ้งผู้ดูแลระบบพร้อมรหัสอ้างอิง"
correlationId="0190b1c2-7d3e-7c41-9a55-3f0e8a11d201"
action={<Component label="ลองอีกครั้ง" icon={RotateCw} onClick={handleClick} />}
/>
</tbody>
</table>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| kind* จำเป็น | "error" | "no-results" | "error" ค่าที่ใช้ได้: "no-results""error" | no-results when nothing matches the search or filters, error when the rows failed to load. |
| colSpan* จำเป็น | 5 | number | The number of columns in the table, so the row spans all of them. |
| title* จำเป็น | "โหลดรายการไม่สำเร็จ" | string | What happened, in a short sentence. |
| body* จำเป็น | "ระบบไม่ตอบสนองในขณะนี้ ลองอีกครั้ง หากยังไม่ได้ แจ้งผู้ดูแลระบบพร้อมรหัสอ้างอิง" | string | What to do next. |
| correlationId | "0190b1c2-7d3e-7c41-9a55-3f0e8a11d201" | string | For an unexpected error: the Correlation ID, so support can trace it. The frontend standard requires it. |
| action | <Component label="ลองอีกครั้ง" icon={RotateCw} onClick={handleClick} /> | ReactNode | The button, such as Clear all filters or Try again. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| kind* จำเป็น | "no-results" | "error" | — | no-results when nothing matches the search or filters, error when the rows failed to load. |
| colSpan* จำเป็น | number | — | The number of columns in the table, so the row spans all of them. |
| title* จำเป็น | string | — | What happened, in a short sentence. |
| body* จำเป็น | string | — | What to do next. |
| correlationId | string | — | For an unexpected error: the Correlation ID, so support can trace it. The frontend standard requires it. |
| action | ReactNode | — | The button, such as Clear all filters or Try again. |
ข้อควรปฏิบัติ
- คงช่องค้นหา เงื่อนไข และชิปตัวกรองไว้บนหน้าจอ แต่ซ่อนตัวแบ่งหน้าและยอดรวม
- บอกสิ่งที่เกิดขึ้นใน title และสิ่งที่ทำต่อได้ใน body ห้ามแสดงข้อความผิดพลาดทางเทคนิค
- บอกผลใน live region ของตารางด้วย เช่น ไม่พบรายการ หรือ โหลดรายการไม่สำเร็จ
- หลังกดลองอีกครั้ง ให้แสดง TableSkeleton จนกว่าข้อมูลจะมา
ซอร์สโค้ด: ui/src/data-table.tsx