جدول البيانات واجهة البرمجة
الخصائص والفتحات والنصوص والتنسيق في جدول البيانات من slotsmith.
الفتحات
في DataTable عدد 24 من الفتحات. مرّر بديلًا لأي منها في components، وكل فتحة لا تمرّرها تبقى على بديلها الافتراضي. فتحات العناصر تستقبل خصائص DOM فيناسبها عنصر المكتبة كما هو، وفتحات الأدوات تستقبل خصائص مسمّاة وتحتاج عادة إلى بضعة أسطر من المحوّل.
| الاسم | النوع | الخصائص التي تستقبلها | البديل الافتراضي | سمات data-* |
|---|---|---|---|---|
Root | <element> | خصائص DOM: | مصدر البديل |
|
Table | <element> | خصائص DOM: | مصدر البديل |
|
Head | <element> | خصائص DOM: | مصدر البديل | — |
Body | <element> | خصائص DOM: | مصدر البديل |
|
HeaderRow | <element> | خصائص DOM: | مصدر البديل |
|
HeaderCell | <element> | خصائص DOM: | مصدر البديل |
|
Foot | <element> | خصائص DOM: | مصدر البديل | — |
FooterRow | <element> | خصائص DOM: | مصدر البديل |
|
FooterCell | <element> | خصائص DOM: | مصدر البديل |
|
Row | <element> | خصائص DOM: | مصدر البديل |
|
Cell | <element> | خصائص DOM: | مصدر البديل |
|
Checkbox | {widget} |
| مصدر البديل | — |
SortTrigger | {widget} |
| مصدر البديل | — |
SortIcon | {widget} |
| مصدر البديل | — |
ExpandToggle | {widget} |
| مصدر البديل |
|
Skeleton | {widget} |
| مصدر البديل | — |
Empty | {widget} |
| مصدر البديل | — |
Error | {widget} |
| مصدر البديل | — |
Pagination | {widget} |
| مصدر البديل | — |
PaginationButton | {widget} |
| مصدر البديل | — |
PageSizeSelect | {widget} |
| مصدر البديل | — |
DragHandle | <element> | خصائص DOM:
| مصدر البديل |
|
CellEditor | {widget} | لا خصائص خاصة بها. | مصدر البديل | — |
FillHandle | <element> | خصائص DOM:
| مصدر البديل |
|
الخصائص
كل خصائص DataTable مجمّعة كما في توثيق المكتبة. الحالة المتحكَّم بها تأتي أزواجًا: مرّر القيمة مع معالج تغييرها، أو القيمة الابتدائية وحدها لتبقى الحالة داخل المكوّن.
| الاسم | النوع | الافتراضي | الوصف |
|---|---|---|---|
| Data | |||
data | T | — | The rows to display. For manual pagination, just the current page. Pass this or |
value | T | — | The rows, for a table people edit: the same as |
columnsمطلوبة | DataTableColumnDef< | — | The column definitions. |
get | ( |
| Stable row identity. Defaults to |
| Sorting | |||
sorting | SortingState | — | Controlled sorting state. |
on | ( | — | Called with the new sorting state. |
default | SortingState | [] | Initial sorting when uncontrolled. Defaults to |
manual | boolean | false | The data arrives already sorted (server-side sorting). Defaults to |
enable | boolean | false | Allow sorting by several columns with shift-click. Defaults to |
| Pagination | |||
pagination | PaginationState | — | Controlled pagination state. |
on | ( | — | Called with the new pagination state. |
default | PaginationState | { | Initial pagination when uncontrolled. Defaults to |
manual | boolean | false | The data is already one page (server-side pagination); pass |
row | number | — | Total rows across all pages, for manual pagination. |
page | number | DEFAULT_ | The page sizes offered. Defaults to DEFAULT_PAGE_SIZE_OPTIONS. |
enable | boolean | true |
|
hide | boolean | — | Hide the pagination UI while still paginating. |
| Selection | |||
enable | boolean | | — | Shows a checkbox column. A function decides per row whether it can be selected. |
selection | T | — | Controlled selection, as row objects. Matched to rows by |
on | ( | — | Called with the selected rows, including rows on other server pages. |
default | T | [] | Initial selection when uncontrolled. Defaults to |
reset | boolean | false | Clear the selection whenever the page or page size changes. Defaults to |
| Tree rows | |||
get | ( | — | Returns a row's children, turning the table into a tree. |
set | ( | — | Writes new children into a copy of a tree row and returns it: how the table builds the new tree after a move across parents ( |
get | ( | — | Decides whether a row can expand, e.g. to lazy-load children. |
expanded | ExpandedState | — | Controlled expansion: |
on | ( | — | Called with the new expansion state. |
default | ExpandedState | { | Initial expansion when uncontrolled. Defaults to |
paginate | boolean | false | Count sub-rows towards the page size. Defaults to |
| Row reordering | |||
enable | boolean | false | Lets rows be dragged into a new order, by pointer, touch or keyboard. In a tree table ( |
on | ( | — | Called when a row is dropped in a new place. The table does not reorder itself: store |
reorder | boolean | true | Adds a leading column with each row's drag handle. |
reorder | ReorderWhileSorted | "clearSort" | What a drop means while a column sort is active. |
reorder | boolean | false | In a tree table, rows may be dragged to another parent and another depth, not only among their siblings: drag sideways (or press the left and right arrow keys while a row is lifted) to move it in or out a level. Needs |
can | ( | — | Whether a dragged row may land at a place; places it may not are skipped while dragging. |
reorder | string | — | Tables with the same |
reorder | string | a generated id | This table's name in transfers between the tables of a reorder group. Defaults to a generated id. |
on | ( | — | Called on both tables when rows move between them: |
| Spreadsheet | |||
spreadsheet | boolean | | false | Spreadsheet mode: cells are selected, navigated and edited with the keyboard and the pointer, copied and pasted as tab-separated text, filled with the fill handle and undone. Columns opt in to editing with |
on | ( | — | Called with the new rows after every edit in spreadsheet mode: typing, paste, cut, Delete, fill, undo and redo. The table never changes the rows itself, so store |
| Status | |||
loading | boolean | false | Shows skeleton rows. Defaults to |
error | unknown | — | Any non-nullish value shows the error state. |
on | ( | — | Shows a retry button in the error state. |
| Rendering | |||
components | Partial< | — | Replace any UI slot; the rest fall back to |
labels | Partial< | — | Override any text, e.g. to translate the table. Wins over |
locale | LocaleInput | the provider's | The language: a locale object, or the tag of one given to |
slot | DataTableSlotProps< | — | Extra DOM props for element slots, e.g. per-row classNames. |
on | DataTableContextValue< | — | Called when a body row is clicked (not its checkbox or expand toggle). |
size | "sm" | | — | Density; sets |
striped | boolean | — | Alternate row backgrounds; sets |
table | Partial< | — | Escape hatch: extra options passed straight to TanStack's |
virtual | DataTableVirtualOptions | — | Renders only the rows in view, for long lists: pass the virtualizer hook ( |
تُمرَّر أي خاصية أخرى إلى العنصر الجذر <div>.
النصوص واللغات
كل نص يعرضه DataTable أو يعلنه، مع قيمته الافتراضية بالإنجليزية. مرّر labels لتغيير بعضها في مكوّن واحد، أو locale لتحويل كل النصوص إلى لغة أخرى. العرض أدناه يفعل الأمرين.
| المفتاح | النوع | الافتراضي بالإنجليزية | الوصف |
|---|---|---|---|
empty | ReactNode | "No data found" | Empty state message. Default: "No data found". |
error | ReactNode | "Something went wrong while loading the data. | Error state message. |
retry | ReactNode | "Retry" | Retry button text. Default: "Retry". |
rows | ReactNode | "Rows per page" | Page-size select label. Default: "Rows per page". |
page | ( | pageInfo(يطبع | Page info. Default: |
pagination | string | "Pagination" | Accessible name of the pagination landmark. |
previous | string | "Previous page" | Accessible name of the previous-page button. |
next | string | "Next page" | Accessible name of the next-page button. |
select | string | "Select all rows on this page" | Accessible name of the select-all checkbox. |
select | string | "Select row" | Accessible name of each row checkbox. |
expand | string | "Expand row" | Accessible name of the expand toggle on a collapsed row. |
collapse | string | "Collapse row" | Accessible name of the expand toggle on an expanded row. |
reorder | string | "Reorder row" | Accessible name of each row's drag handle. Default: "Reorder row". |
reorder | string | "Press space to lift the row, | How to move a row with the keyboard, given to assistive technology with the drag handle. |
reorder | ( | reorderLifted(يطبع | Announced when a row is lifted. Default: |
reorder | ( | reorderMoved(يطبع | Announced on each keyboard step. Default: |
reorder | ( | reorderDropped(يطبع | Announced when a row is dropped. Default: |
reorder | string | "Reordering cancelled. | Announced when a move is cancelled. Default: "Reordering cancelled." |
reorder | ( | reorderLevel(يطبع | Announced after a step or a drop that moves a row across parents, with its depth from 1. Default: |
edit | ( | editCell(يطبع | Spreadsheet mode: the cell editor's accessible name. Default: |
invalid | string | "Enter a number. | Spreadsheet mode: a number cell got text that is not a number. Default: "Enter a number." |
invalid | string | "Choose one of the options. | Spreadsheet mode: a select cell got text that matches no option. Default: "Choose one of the options." |
invalid | string | "Enter a valid date. | Spreadsheet mode: a date cell got text that is not a date. Default: "Enter a valid date." |
invalid | string | "Enter TRUE or FALSE. | Spreadsheet mode: a checkbox cell got text that is neither true nor false. Default: "Enter TRUE or FALSE." |
cells | ( | cellsCopied(يطبع | Spreadsheet mode: announced after a copy. Default: |
cells | ( | cellsCut(يطبع | Spreadsheet mode: announced after a cut. Default: |
cells | ( | cellsPasted(يطبع | Spreadsheet mode: announced after a paste; |
cells | ( | cellsCleared(يطبع | Spreadsheet mode: announced after Delete. Default: |
cells | ( | cellsFilled(يطبع | Spreadsheet mode: announced after a fill. Default: |
undone | string | "Undone. | Spreadsheet mode: announced after an undo. Default: "Undone." |
redone | string | "Redone. | Spreadsheet mode: announced after a redo. Default: "Redone." |
| Der Process | Franz Kafka | 1925 |
| Effi Briest | Theodor Fontane | 1896 |
| Der Steppenwolf | Hermann Hesse | 1927 |
import { DataTable, type DataTableColumnDef } from "slotsmith/data-table";
import { de } from "slotsmith/locales/de";
type Book = { id: string; title: string; author: string; year: number };
const books: Book[] = [
{ id: "1", title: "Der Process", author: "Franz Kafka", year: 1925 },
{ id: "2", title: "Effi Briest", author: "Theodor Fontane", year: 1896 },
{ id: "3", title: "Der Steppenwolf", author: "Hermann Hesse", year: 1927 },
{ id: "4", title: "Buddenbrooks", author: "Thomas Mann", year: 1901 },
{ id: "5", title: "Momo", author: "Michael Ende", year: 1973 },
];
const columns: DataTableColumnDef<Book>[] = [
{ accessorKey: "title", header: "Titel" },
{ accessorKey: "author", header: "Autor" },
{ accessorKey: "year", header: "Jahr" },
];
export default function Labels() {
return (
<DataTable
data={books}
columns={columns}
// Every string in German, from the ready-made pack…
locale={de}
// …except the page counter, replaced for this table only.
labels={{ pageInfo: (page, pageCount) => `${page} / ${pageCount}` }}
defaultPagination={{ pageIndex: 0, pageSize: 3 }}
pageSizeOptions={[3, 5]}
/>
);
}حزم اللغات الجاهزة ودعم الكتابة من اليمين إلى اليسار واللغة على مستوى التطبيق موضّحة في صفحة اللغات.
التنسيق
أسماء الأصناف التي تضعها البدائل الافتراضية في DataTable على عناصرها، والمتغيرات التي يقرؤها ملف تنسيقه. اضبط متغيرًا على المكوّن أو على أي عنصر يحيط به لتغيير مظهره، واستهدف الصنف فقط لما لا يغطيه متغير.
| الصنف | الفتحة |
|---|---|
.sdt | |
.sdt__scroll | — |
.sdt__table | |
.sdt__head | |
.sdt__body | |
.sdt__foot | |
.sdt__row | |
.sdt__cell | |
.sdt__cell--drag | — |
.sdt__cell--select | — |
.sdt__checkbox | |
.sdt__sort | |
.sdt__sort-icon | |
.sdt__tree | — |
.sdt__tree-spacer | — |
.sdt__expand | |
.sdt__skeleton | |
.sdt__message | |
.sdt__error | |
.sdt__button | — |
.sdt__button--icon | |
.sdt__pagination | |
.sdt__pagination-buttons | — |
.sdt__pagination-info | — |
.sdt__page-size | |
.sdt__page-size-select | — |
.sdt__drag | |
.sdt__editor-host | — |
.sdt__cell-ghost | — |
.sdt__checkbox-cell | — |
.sdt__editor | |
.sdt__editor-input | — |
.sdt__editor-control | — |
.sdt__editor-trigger | — |
.sdt__editor-error | — |
.sdt__fill-handle | |
.sdt__sr-only | — |
| المتغير | الطبقة |
|---|---|
--sdt-accent | هذا المكوّن |
--sdt-bg | هذا المكوّن |
--sdt-border | هذا المكوّن |
--sdt-checkbox-size | هذا المكوّن |
--sdt-danger | هذا المكوّن |
--sdt-font-size | هذا المكوّن |
--sdt-header-bg | هذا المكوّن |
--sdt-hover | هذا المكوّن |
--sdt-max-height | هذا المكوّن |
--sdt-muted | هذا المكوّن |
--sdt-padding-x | هذا المكوّن |
--sdt-padding-y | هذا المكوّن |
--sdt-radius | هذا المكوّن |
--sdt-selected | هذا المكوّن |
--sdt-skeleton-bg | هذا المكوّن |
--sdt-skeleton-bg-2 | هذا المكوّن |
--sdt-stripe | هذا المكوّن |
--sdt-surface | هذا المكوّن |
--sdt-text | هذا المكوّن |
--ss-accent | مشترك بين كل المكوّنات |
--ss-border | مشترك بين كل المكوّنات |
--ss-danger | مشترك بين كل المكوّنات |
--ss-font-size | مشترك بين كل المكوّنات |
--ss-hover | مشترك بين كل المكوّنات |
--ss-muted | مشترك بين كل المكوّنات |
--ss-radius | مشترك بين كل المكوّنات |
--ss-selected | مشترك بين كل المكوّنات |
--ss-surface | مشترك بين كل المكوّنات |
--ss-text | مشترك بين كل المكوّنات |
تنتقل كل المتغيرات إلى قيمها الداكنة تحت .dark, [data-theme="dark"]، على الصفحة أو على أي عنصر يحيط بالمكوّن.