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

ตารางระหว่างโหลด

TableSkeleton

Placeholder rows for the first load, keeping the table's real columns. Set aria-busy on the table while they show, and say the table is loading in its live region. Show no pager or total until the rows arrive.

ใช้ในเนื้อตารางตอนโหลดข้อมูลครั้งแรก แทนแถวจริง โดยคงคอลัมน์เดิมไว้ ส่งคอลัมน์ให้ตรงกับหัวตาราง ถ้าโหลดใหม่ระหว่างที่แถวแสดงอยู่แล้ว ให้คงแถวเดิมไว้ ถ้าเป็นการ์ดหรือบล็อกที่ไม่ใช่ตาราง ใช้ Skeleton ตอนนี้หน้าจอยังต้องเขียนตาราง data-table หัวตาราง และ tbody เอง

import { TableSkeleton } from "@bsru/ui";

ตัวอย่าง

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

box สำหรับช่องเลือกและปุ่มไอคอน money ชิดขวา label แสดงข้างแถบเมื่อแถวเรียงซ้อนบนมือถือ ค่าเริ่มต้นแสดง 5 แถว

กำลังโหลดรายการ
เลือกเลขที่รายการหน่วยงานวันที่วงเงิน (บาท)สถานะจัดการ
const columns = [
  { box: true, label: "เลือก" },
  { label: "เลขที่", className: "whitespace-nowrap" },
  { label: "รายการ" },
  { label: "หน่วยงาน" },
  { label: "วันที่", className: "whitespace-nowrap" },
  { label: "วงเงิน (บาท)", money: true },
  { label: "สถานะ" },
  { box: true, className: "max-md:hidden" },
];

// Today the screen still writes the table. A data-driven DataTable is coming next.
<table className="data-table stack-table" aria-busy={loading}>
  <thead>...</thead>
  <tbody>
    {loading ? <TableSkeleton columns={columns} /> : requests.map(...)}
  </tbody>
</table>

ตารางเล็ก

ส่ง rows ให้ใกล้เคียงจำนวนแถวที่คาดว่าจะได้ เพื่อให้หน้าไม่กระโดดเมื่อข้อมูลมาถึง

กำลังโหลดรายการ
รหัสงบประมาณแหล่งเงินคงเหลือ (บาท)
const columns = [
  { label: "รหัสงบประมาณ" },
  { label: "แหล่งเงิน" },
  { label: "คงเหลือ (บาท)", money: true },
];

// Today the screen still writes the table. A data-driven DataTable is coming next.
<table className="data-table stack-table" aria-busy={loading}>
  <thead>...</thead>
  <tbody>
    {loading ? <TableSkeleton columns={columns} rows={3} /> : requests.map(...)}
  </tbody>
</table>

props ทั้งหมด

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

TableSkeleton props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
columns* จำเป็นreadonly TableSkeletonColumn[]—One entry for each of the table's columns, so the placeholder lines up with the headings.
rowsnumber5How many placeholder rows to show.

ชนิดข้อมูล

TableSkeletonColumn

One column of placeholder rows. List them in the same order as the table's headings.

TableSkeletonColumn fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
labelstring—The column name, shown beside the bar when rows stack at phone width.
moneyboolean—A right-aligned money column.
boxboolean—A small square, for a checkbox or an icon button.
classNamestring—Classes for the cell, such as max-md:hidden.

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

  • ตั้ง aria-busy บนตารางระหว่างโหลด และบอกว่ากำลังโหลดใน live region ของตาราง
  • ระหว่างโหลดไม่แสดงตัวแบ่งหน้า ยอดรวม หรือแถบจัดการหลายรายการ แต่คงช่องค้นหาและตัวกรองไว้
  • columns ต้องมีจำนวนและลำดับเท่ากับหัวตาราง

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