รายการสินค้า
LineItems
The lines of a request or document, with money right-aligned and a total row. Pass the total from the core API, so it always matches the record's amount.
เลิกใช้แล้ว
Since 0.29.0. Use DataTable with paged={false}: a number column with unit for the quantity, money columns for the unit price and amount with total: true on the amount, totals with the record's total, and totalLabel. Removed in 1.0.0.
เลิกใช้แล้วตั้งแต่ 0.29.0 และจะถูกนำออกใน 1.0.0 รายการสินค้าหรือบริการในคำขอหรือเอกสาร ให้ใช้ DataTable ที่ส่ง paged={false} เพื่อแสดงทุกแถวโดยไม่มีตัวแบ่งหน้า คอลัมน์จำนวนเป็น kind number พร้อม unit ราคาต่อหน่วยและจำนวนเงินเป็น kind money โดยจำนวนเงินมี total: true แล้วส่งยอดรวมจาก core API ใน totals พร้อม totalLabel LineItems ยังใช้ได้จนถึง 1.0.0
import { LineItems } from "@bsru/ui";ตัวอย่าง
รายการในคำขอซื้อ ด้วย DataTable
unit ของคอลัมน์จำนวนชี้ไปที่ฟิลด์ unit ของแถว จึงแสดง 5 เครื่อง totals มาจาก core API จึงตรงกับยอดของคำขอเสมอ บนมือถือแต่ละแถวเรียงซ้อนพร้อมชื่อคอลัมน์ และแถวรวมแสดงต่อท้าย
พบ 3 รายการ
| รายการ | จำนวน | ราคาต่อหน่วย | จำนวนเงิน (บาท) |
|---|---|---|---|
| คอมพิวเตอร์โน้ตบุ๊ก | 5 เครื่อง | 27,000.00 | 135,000.00 |
| กระเป๋าใส่โน้ตบุ๊ก | 5 ใบ | 1,000.00 | 5,000.00 |
| ติดตั้งและตั้งค่าซอฟต์แวร์ | 1 งาน | 10,000.00 | 10,000.00 |
| รวมทั้งสิ้น | 150,000.00 | ||
const lineColumns: DataColumn<Line>[] = [
{ key: "description", label: "รายการ" },
{ key: "quantity", label: "จำนวน", kind: "number", unit: "unit" },
{ key: "unitPrice", label: "ราคาต่อหน่วย", kind: "money" },
{
key: "amount",
label: "จำนวนเงิน (บาท)",
kind: "money",
total: true,
},
];
<DataTable
caption="รายการในคำขอ PR-2570-0001"
columns={lineColumns}
rows={record.lines}
rowKey="key"
paged={false}
totals={{ amount: record.total }}
totalLabel="รวมทั้งสิ้น"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "รายการในคำขอ PR-2570-0001" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 4 รายการ[
{ key: "description", label: "รายการ" },
{ key: "quantity", label: "จำนวน", kind: "number", unit: "unit" },
{ key: "unitPrice", label: "ราคาต่อหน่วย", kind: "money" },
{
key: "amount",
label: "จำนวนเงิน (บาท)",
kind: "money",
total: true,
},
] | readonly DataColumn<R>[] | — |
| rows* จำเป็น | รายการ 3 รายการ[
{
key: "1",
description: "คอมพิวเตอร์โน้ตบุ๊ก",
quantity: 5,
unit: "เครื่อง",
unitPrice: 27000,
amount: 135000,
},
{
key: "2",
description: "กระเป๋าใส่โน้ตบุ๊ก",
quantity: 5,
unit: "ใบ",
unitPrice: 1000,
amount: 5000,
},
{
key: "3",
description: "ติดตั้งและตั้งค่าซอฟต์แวร์",
quantity: 1,
unit: "งาน",
unitPrice: 10000,
amount: 10000,
},
] | readonly R[] | All rows. With total set, only the rows of the current page. |
| rowKey* จำเป็น | "key" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| paged | false | boolean | false shows every row, with no range text, page size or pager, for a short list that belongs to one record, such as the lines of a purchase request. true by default. Ignored with total. |
| totals | { amount: 150000 } | Readonly<Partial<Record<keyof R & string, number>>> | Totals from the core API, by column key, shown in the total row. Pass them for a list the core API pages, and for a record's lines, so the total matches the record's amount. A total column without one here is added up from the rows, except in a list the core API pages. |
| totalLabel | "รวมทั้งสิ้น" | string | Labels the total row. รวมทุกหน้า by default, or รวม with paged false. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
ไม่มีหน่วย
แถวที่ไม่มี unit แสดงเฉพาะตัวเลข
พบ 2 รายการ
| รายการ | จำนวน | ราคาต่อหน่วย | จำนวนเงิน (บาท) |
|---|---|---|---|
| จ้างซ่อมเครื่องปรับอากาศ อาคาร 2 | 3 | 12,500.00 | 37,500.00 |
| ค่าอะไหล่ | 1 | 6,000.00 | 6,000.00 |
| รวมทั้งสิ้น | 43,500.00 | ||
const lineColumns: DataColumn<Line>[] = [
{ key: "description", label: "รายการ" },
{ key: "quantity", label: "จำนวน", kind: "number", unit: "unit" },
{ key: "unitPrice", label: "ราคาต่อหน่วย", kind: "money" },
{
key: "amount",
label: "จำนวนเงิน (บาท)",
kind: "money",
total: true,
},
];
<DataTable
caption="รายการในคำขอ PR-2570-0004"
columns={lineColumns}
rows={record.lines}
rowKey="key"
paged={false}
totals={{ amount: record.total }}
totalLabel="รวมทั้งสิ้น"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "รายการในคำขอ PR-2570-0004" | string | Names the table for screen readers, such as คำขอซื้อขอจ้าง. |
| columns* จำเป็น | รายการ 4 รายการ[
{ key: "description", label: "รายการ" },
{ key: "quantity", label: "จำนวน", kind: "number", unit: "unit" },
{ key: "unitPrice", label: "ราคาต่อหน่วย", kind: "money" },
{
key: "amount",
label: "จำนวนเงิน (บาท)",
kind: "money",
total: true,
},
] | readonly DataColumn<R>[] | — |
| rows* จำเป็น | รายการ 2 รายการ[
{
key: "1",
description: "จ้างซ่อมเครื่องปรับอากาศ อาคาร 2",
quantity: 3,
unitPrice: 12500,
amount: 37500,
},
{
key: "2",
description: "ค่าอะไหล่",
quantity: 1,
unitPrice: 6000,
amount: 6000,
},
] | readonly R[] | All rows. With total set, only the rows of the current page. |
| rowKey* จำเป็น | "key" | keyof R & string | The field that identifies a row, such as no. Selection and onOpen use its value. |
| paged | false | boolean | false shows every row, with no range text, page size or pager, for a short list that belongs to one record, such as the lines of a purchase request. true by default. Ignored with total. |
| totals | { amount: 43500 } | Readonly<Partial<Record<keyof R & string, number>>> | Totals from the core API, by column key, shown in the total row. Pass them for a list the core API pages, and for a record's lines, so the total matches the record's amount. A total column without one here is added up from the rows, except in a list the core API pages. |
| totalLabel | "รวมทั้งสิ้น" | string | Labels the total row. รวมทุกหน้า by default, or รวม with paged false. |
| onSortChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: TableSort) => void | Hears every sort change. Go back to page 1. |
| onPageChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onPageSizeChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | — |
| onOpen | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => void | Opens a row, from the value in an opens column and a quick-view button. Use for a drawer. |
| openHref | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The URL of a row's record page. The value in an opens column becomes a link. |
| openLabel | ไม่ได้ส่งในตัวอย่างนี้ | (row: R) => string | The quick-view button's accessible name for a row. ดูรายละเอียด and the row key by default. |
LineItems ที่เลิกใช้แล้ว
วิธีเดิม ซึ่งแสดงผลเหมือนตัวอย่างแรก ย้ายไปใช้ DataTable ตามหมายเหตุด้านล่าง
| รายการ | จำนวน | ราคาต่อหน่วย | จำนวนเงิน (บาท) |
|---|---|---|---|
| คอมพิวเตอร์โน้ตบุ๊ก | 5 เครื่อง | 27,000.00 | 135,000.00 |
| กระเป๋าใส่โน้ตบุ๊ก | 5 ใบ | 1,000.00 | 5,000.00 |
| ติดตั้งและตั้งค่าซอฟต์แวร์ | 1 งาน | 10,000.00 | 10,000.00 |
| รวมทั้งสิ้น | 150,000.00 | ||
<LineItems
caption="รายการในคำขอ PR-2570-0001"
columns={{
description: "รายการ",
quantity: "จำนวน",
unitPrice: "ราคาต่อหน่วย",
amount: "จำนวนเงิน (บาท)",
}}
items={[
{
key: "1",
description: "คอมพิวเตอร์โน้ตบุ๊ก",
quantity: 5,
unit: "เครื่อง",
unitPrice: 27000,
amount: 135000,
},
{
key: "2",
description: "กระเป๋าใส่โน้ตบุ๊ก",
quantity: 5,
unit: "ใบ",
unitPrice: 1000,
amount: 5000,
},
{
key: "3",
description: "ติดตั้งและตั้งค่าซอฟต์แวร์",
quantity: 1,
unit: "งาน",
unitPrice: 10000,
amount: 10000,
},
]}
totalLabel="รวมทั้งสิ้น"
total={150000}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | "รายการในคำขอ PR-2570-0001" | string | Names the table for screen readers, such as รายการในคำขอ PR-2570-0001. |
| columns* จำเป็น | ออบเจกต์ 4 ฟิลด์{
description: "รายการ",
quantity: "จำนวน",
unitPrice: "ราคาต่อหน่วย",
amount: "จำนวนเงิน (บาท)",
} | { description: string; quantity: string; unitPrice: string; amount: string } | The four column headings, already in the screen language. |
| items* จำเป็น | รายการ 3 รายการ[
{
key: "1",
description: "คอมพิวเตอร์โน้ตบุ๊ก",
quantity: 5,
unit: "เครื่อง",
unitPrice: 27000,
amount: 135000,
},
{
key: "2",
description: "กระเป๋าใส่โน้ตบุ๊ก",
quantity: 5,
unit: "ใบ",
unitPrice: 1000,
amount: 5000,
},
{
key: "3",
description: "ติดตั้งและตั้งค่าซอฟต์แวร์",
quantity: 1,
unit: "งาน",
unitPrice: 10000,
amount: 10000,
},
] | readonly LineItem[] | The lines, in order. |
| totalLabel* จำเป็น | "รวมทั้งสิ้น" | string | The label of the total row, such as รวมทั้งสิ้น. |
| total* จำเป็น | 150000 | number | The record's total in baht, from the core API. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| caption* จำเป็น | string | — | Names the table for screen readers, such as รายการในคำขอ PR-2570-0001. |
| columns* จำเป็น | { description: string; quantity: string; unitPrice: string; amount: string } | — | The four column headings, already in the screen language. |
| items* จำเป็น | readonly LineItem[] | — | The lines, in order. |
| totalLabel* จำเป็น | string | — | The label of the total row, such as รวมทั้งสิ้น. |
| total* จำเป็น | number | — | The record's total in baht, from the core API. |
ชนิดข้อมูล
LineItem
One line of a request or document.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| key* จำเป็น | string | — | Unique among the lines, such as the line number. |
| description* จำเป็น | string | — | What the line is for. |
| quantity* จำเป็น | number | — | How many, as a number. The unit follows it. |
| unit | string | — | The unit after the quantity, such as เครื่อง. |
| unitPrice* จำเป็น | number | — | The price of one unit in baht, as a number. The list formats it. |
| amount* จำเป็น | number | — | From the core API. The screen never works out money. |
DataColumn
One column of a DataTable. The table reads the value from each row by key, and formats it by kind.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| key* จำเป็น | keyof R & string | — | The row field to show. It also names the column when sorting, and in a server query. |
| label* จำเป็น | string | — | The heading, already in the screen language. At phone width it labels the value in each row. |
| kind | ColumnKind ค่าที่ใช้ได้: "text""number""money""date""badge" | — | text by default. A text value may be a string or a Text pair. number and money take numbers, and money shows two decimals. date takes an ISO date such as 2026-11-02. badge looks the value up in badges. |
| sortable | boolean | — | People can sort by this column. In a table that has every row and pages them, every column sorts unless this is false. With total the core API sorts, so only columns with true sort, and the screen handles onSortChange. With paged false, a record's lines keep their order unless this is true. |
| searchable | boolean | — | The search box looks in this column. Text columns are searched unless this is false. |
| badges | Readonly<Record<string, BadgeStyle>> | — | For a badge column: how each value shows, such as { pending: { tone: "pending", label: "รออนุมัติ" } }. |
| sub | keyof R & string | — | Another row field, shown as a smaller second line, such as a vendor code under the vendor name. |
| avatar | boolean | — | Shows the value's initials in a round tile before it, such as for a person's or a unit's name. |
| opens | boolean | — | The value opens the row, through the table's onOpen or openHref. Usually the record number. |
| total | boolean | — | Adds the column up in the total row. For number and money columns. |
| unit | keyof R & string | — | Another row field, shown after a number or money value, such as เครื่อง after a quantity of 5. The value keeps its own formatting and alignment, and sorting and the total use the number alone. |
| hideOnPhone | boolean | — | Hides the column at phone width, where each row becomes a block. |
Text
A string in both languages. Thai comes first because it is the default.
type Text = readonly [th: string, en: string];ColumnKind
How a column shows its value.
type ColumnKind = "text" | "number" | "money" | "date" | "badge";BadgeStyle
How a badge column shows one value, such as pending.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| tone* จำเป็น | BadgeTone ค่าที่ใช้ได้: "draft""pending""approved""paid""request""rejected""line" | — | — |
| label* จำเป็น | string | — | The badge text, already in the screen language. |
| icon | LucideIcon | — | — |
BadgeTone
The state a badge reports. Each one has its own colour. line is for facts that aren't a state.
type BadgeTone = "draft" | "pending" | "approved" | "paid" | "request" | "rejected" | "line";TableSearch
The search box above the table.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| placeholder* จำเป็น | string | — | Says what can be searched, such as ค้นหาเลขที่หรือรายการ. It is also the box's accessible name. |
| value | string | — | The search text, when the screen keeps it. |
| onChange | (q: string) => void | — | Hears the search text. With total set, it comes after a short pause, ready for a query to the core API. |
TableFilters
The filters in the filter bar above the table, and a chip for each one in use.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| chips* จำเป็น | readonly FilterChip[] | — | The filters in use, one chip each. Removing one should go back to page 1. |
| onClearAll* จำเป็น | () => void | — | Called by Clear all. Remove every filter, including those without a chip, such as putting a Segmented back on its All choice, but keep the search text. |
| active | boolean | — | The filters on the bar are narrowing the list, even where a filter has no chip, such as a Segmented that isn't on its All choice. With no rows, the table then says nothing matches the filters, keeps the bar and offers Clear all, instead of showing empty as if nothing existed yet. True whenever chips has any. |
| panel | ReactNode | — | The filters, built from the library's fields, shown in one row on the left of the filter bar, with the search box on the right. Use compact fields: a Select, Combobox or DateInput with hideLabel and a placeholder that names the filter, and a Segmented with a count on each choice. |
FilterChip
One filter in use, shown as a chip.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| key* จำเป็น | string | — | Unique among the chips, such as status-pending. |
| label* จำเป็น | string | — | What the filter is, already in the screen language and formatted, such as a date range. |
| onRemove* จำเป็น | () => void | — | Called when the chip's remove button is pressed. Remove the filter and go back to page 1. |
TableSort
The column a table is sorted by, and which way.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| key* จำเป็น | string | — | — |
| dir* จำเป็น | SortDir ค่าที่ใช้ได้: "asc""desc" | — | — |
SortDir
The sort direction: asc for A to Z and smallest first, desc for the reverse.
type SortDir = "asc" | "desc";TableSelection
Row selection, with actions on the chosen rows.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| selected | readonly string[] | — | The chosen rows' keys, when the screen keeps them. |
| onChange | (keys: string[]) => void | — | Hears the chosen keys after every change. |
| actions* จำเป็น | readonly BulkAction[] | — | The actions on the chosen rows, such as Export. |
BulkAction
An action on the chosen rows, shown in the bar above the table while any row is chosen.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| label* จำเป็น | string | — | The button text, already in the screen language. |
| icon | LucideIcon | — | — |
| tone | "primary" | "secondary" | "danger" | — | secondary by default. |
| onRun* จำเป็น | (keys: string[]) => void | — | Gets the keys of every chosen row, across all pages. |
TableError
What the table shows instead of rows when they failed to load.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| title* จำเป็น | string | — | What happened, in a short sentence. |
| body* จำเป็น | string | — | What to do next. |
| correlationId | string | — | The Correlation ID of the failed request, so support can trace it. |
| onRetry | () => void | — | Called by Try again. Leave out when trying again can't help. |
TableEmpty
What the table shows when nothing exists yet, before anyone has created a record.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| title* จำเป็น | string | — | Says there are no records yet, such as ยังไม่มีคำขอซื้อขอจ้าง. |
| body* จำเป็น | string | — | Says what will appear here, and how it gets here. |
| icon | LucideIcon | — | A Lucide icon for the kind of record. |
| action | TableAction | — | The button that creates the first record. Leave out for people who may not create one. |
TableAction
A button the table shows, such as Try again or Create request.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| label* จำเป็น | string | — | The button text, already in the screen language. |
| icon | LucideIcon | — | — |
| tone | "primary" | "secondary" | "danger" | — | secondary by default. Use primary for the one main action, and danger for one that deletes. |
| onClick* จำเป็น | () => void | — | — |
ข้อควรปฏิบัติ
- ย้ายจาก LineItems: columns ที่เป็นออบเจกต์หัวคอลัมน์สี่ช่อง กลายเป็นอาร์เรย์ DataColumn สี่คอลัมน์ items เป็น rows พร้อม rowKey="key" total={x} เป็น totals={{ amount: x }} และเพิ่ม paged={false} ส่วน caption และ totalLabel เหมือนเดิม
- หน้าจอไม่คำนวณเงินเอง amount และ totals มาจาก core API เพื่อให้ตรงกับยอดของรายการเสมอ
- ส่งเงินเป็น number ในหน่วยบาท ตารางแสดงทศนิยมสองตำแหน่งและตัวคั่นหลักพันเอง
- caption ตั้งชื่อตารางให้โปรแกรมอ่านหน้าจอ ใส่เลขที่ของเอกสารด้วย
ซอร์สโค้ด: ui/src/record.tsx