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

สถานะของตาราง

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>

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

ข้อผิดพลาดที่ไม่คาดคิดต้องแสดงรหัสอ้างอิง (Correlation ID) จาก core API เพื่อให้ผู้ดูแลระบบตามได้ และมีปุ่มลองอีกครั้ง

คำขอซื้อขอจ้าง
เลขที่รายการหน่วยงานวงเงิน (บาท)สถานะ

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

ระบบไม่ตอบสนองในขณะนี้ ลองอีกครั้ง หากยังไม่ได้ แจ้งผู้ดูแลระบบพร้อมรหัสอ้างอิง

รหัสอ้างอิง 0190b1c2-7d3e-7c41-9a55-3f0e8a11d201

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

props ทั้งหมด

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

TableState 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.
correlationIdstring—For an unexpected error: the Correlation ID, so support can trace it. The frontend standard requires it.
actionReactNode—The button, such as Clear all filters or Try again.

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

  • คงช่องค้นหา เงื่อนไข และชิปตัวกรองไว้บนหน้าจอ แต่ซ่อนตัวแบ่งหน้าและยอดรวม
  • บอกสิ่งที่เกิดขึ้นใน title และสิ่งที่ทำต่อได้ใน body ห้ามแสดงข้อความผิดพลาดทางเทคนิค
  • บอกผลใน live region ของตารางด้วย เช่น ไม่พบรายการ หรือ โหลดรายการไม่สำเร็จ
  • หลังกดลองอีกครั้ง ให้แสดง TableSkeleton จนกว่าข้อมูลจะมา

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