ตารางระหว่างโหลด
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>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| columns* จำเป็น | รายการ 8 รายการ[
{ box: true, label: "เลือก" },
{ label: "เลขที่", className: "whitespace-nowrap" },
{ label: "รายการ" },
{ label: "หน่วยงาน" },
{ label: "วันที่", className: "whitespace-nowrap" },
{ label: "วงเงิน (บาท)", money: true },
{ label: "สถานะ" },
{ box: true, className: "max-md:hidden" },
] | readonly TableSkeletonColumn[] | One entry for each of the table's columns, so the placeholder lines up with the headings. |
ตารางเล็ก
ส่ง 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>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| columns* จำเป็น | รายการ 3 รายการ[
{ label: "รหัสงบประมาณ" },
{ label: "แหล่งเงิน" },
{ label: "คงเหลือ (บาท)", money: true },
] | readonly TableSkeletonColumn[] | One entry for each of the table's columns, so the placeholder lines up with the headings. |
| rows | 3 | number | How many placeholder rows to show. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| columns* จำเป็น | readonly TableSkeletonColumn[] | — | One entry for each of the table's columns, so the placeholder lines up with the headings. |
| rows | number | 5 | How many placeholder rows to show. |
ชนิดข้อมูล
TableSkeletonColumn
One column of placeholder rows. List them in the same order as the table's headings.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| label | string | — | The column name, shown beside the bar when rows stack at phone width. |
| money | boolean | — | A right-aligned money column. |
| box | boolean | — | A small square, for a checkbox or an icon button. |
| className | string | — | Classes for the cell, such as max-md:hidden. |
ข้อควรปฏิบัติ
- ตั้ง aria-busy บนตารางระหว่างโหลด และบอกว่ากำลังโหลดใน live region ของตาราง
- ระหว่างโหลดไม่แสดงตัวแบ่งหน้า ยอดรวม หรือแถบจัดการหลายรายการ แต่คงช่องค้นหาและตัวกรองไว้
- columns ต้องมีจำนวนและลำดับเท่ากับหัวตาราง
ซอร์สโค้ด: ui/src/data-table.tsx