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

แถบจัดการหลายรายการ

BulkBar

A bar for actions on the chosen rows, with the count and Clear selection. Hidden when nothing is chosen.

ใช้เหนือตารางข้อมูลเมื่อผู้ใช้เลือกหลายแถวแล้วทำคำสั่งเดียวกันกับทุกแถว เช่น ส่งออก ส่งจำนวนที่เลือกและปุ่มคำสั่ง แถบซ่อนเองเมื่อไม่มีแถวที่เลือก คำสั่งสำหรับรายการเดียวให้อยู่ในแถวหรือในหน้ารายละเอียด ส่งปุ่มคำสั่งเป็น Button ขนาด sm ตอนนี้หน้าจอยังต้องเขียนตารางและช่องเลือกเอง

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

ตัวอย่าง

เลือกแถวในตาราง

หน้าจอเก็บเลขที่ของแถวที่เลือกไว้ใน Set แล้วส่ง count ลองเลือกหรือยกเลิก แถบจะซ่อนเมื่อไม่มีแถวที่เลือก

เลือกแล้ว 2 รายการ
คำขอซื้อขอจ้าง
เลขที่รายการวงเงิน (บาท)
PR-2570-0003วัสดุสำนักงาน19,500.00
PR-2570-0004จ้างซ่อมเครื่องปรับอากาศ43,500.00
PR-2570-0005โต๊ะและเก้าอี้ห้องเรียน88,000.00
const [picked, setPicked] = useState(new Set(["PR-2570-0003", "PR-2570-0005"]));

<BulkBar count={picked.size} onClear={() => setPicked(new Set())}>
  <Button label="ส่งออก" icon={Download} size="sm" onClick={exportPicked} />
</BulkBar>

// Today the screen still writes the table and its select boxes. A data-driven DataTable is coming next.
<table className="data-table">
  <thead>
    <tr>
      <th className="w-10">
        <Checkbox aria-label="เลือกทุกแถวในหน้านี้" checked={all} indeterminate={some && !all} onChange={pickAll} />
      </th>
      ...
    </tr>
  </thead>
  <tbody>
    {rows.map((r) => (
      <tr key={r.no} data-selected={picked.has(r.no)}>
        <td>
          <Checkbox aria-label={`เลือก ${r.no}`} checked={picked.has(r.no)} onChange={(e) => pick(r.no, e.target.checked)} />
        </td>
        ...
      </tr>
    ))}
  </tbody>
</table>

หลายคำสั่ง

ส่ง Button ขนาด sm เป็น children เรียงตามลำดับที่ใช้บ่อย ยกเลิกการเลือกอยู่ท้ายเสมอ ตัวอย่างนี้ไม่เก็บ state จึงกดแล้วไม่เปลี่ยน

เลือกแล้ว 3 รายการ
<BulkBar count={3} onClear={handleClear}>
  <Component label="ส่งออก" icon={Download} size="sm" />
  <Component label="อนุมัติ" tone="primary" icon={Check} size="sm" />
</BulkBar>

props ทั้งหมด

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

BulkBar props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
count* จำเป็นnumber—How many rows are chosen, across all pages. The bar hides at 0.
onClear* จำเป็น() => void—Called by Clear selection. Empty the selection.
children* จำเป็นReactNode—The actions, such as Export.
classNamestring"flex flex-wrap items-center gap-3 rounded-control soft-green bg-green-100 px-3 py-2"Classes for the bar, such as a top margin.

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

  • count คือจำนวนที่เลือกทั้งหมดทุกหน้า การเปลี่ยนหน้าหรือการเรียงไม่ล้างการเลือก
  • ช่องเลือกทุกแถวที่หัวตารางเลือกเฉพาะแถวในหน้านี้ และแสดงสถานะผสมเมื่อเลือกบางแถว
  • ทุกช่องเลือกต้องมี aria-label ที่บอกว่าเลือกแถวไหน เช่น เลือก PR-2570-0003
  • คำสั่งที่ย้อนกลับไม่ได้ เช่น ลบ ต้องถามยืนยันใน Dialog ก่อน

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