You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/ctablex-table/docs/COMPONENTS.md
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,15 +89,13 @@ The `data` prop takes precedence. Children receive `inner` instead of `outer`.
89
89
90
90
**Using with data fetching components:**
91
91
92
-
A recommended pattern is to fetch and provide data via content context in a separate component:
93
-
94
92
```tsx
95
93
<UserDataProvider>
96
94
<DataTable>{/* Children */}</DataTable>
97
95
</UserDataProvider>
98
96
```
99
97
100
-
`<UserDataProvider />` fetches user data and provides it via content context. `<DataTable>`consumes this data without needing a `data` prop. This approach keeps the component tree constant, as no data prop is passed down, which can improve performance and simplify component composition.
98
+
`<UserDataProvider>` fetches and provides user data via content context. `<DataTable>`uses that data without needing a `data` prop.
Copy file name to clipboardExpand all lines: packages/ctablex-table/docs/OVERVIEW.md
+47-7Lines changed: 47 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@ This document provides an example and shows how it works, then step by step show
5
5
## TL;DR
6
6
7
7
-**Basic example and component expansion**: See how a simple `<Table />` component automatically expands into `<TableHeader />`, `<TableBody />`, rows, and cells through default children
8
+
-**Data providing patterns**: Learn three ways to provide data to the table—via `data` prop, content context, or data provider components
8
9
-**Customize cell content**: Learn to create custom content components like `NumberContent` that read from context and format data your way
9
10
-**Customize elements**: Discover how to swap default HTML elements using `TableElementsProvider` or the `el` prop to match your design system
10
11
-**Customize structure**: Explore techniques for changing table structure—add footers, remove headers, render multiple rows per item, or replace the table entirely with custom layouts
This results in the final rendered table as shown in the basic example.
333
334
335
+
## Data Providing Patterns
336
+
337
+
There are three ways to provide data to the table, each suited for different scenarios.
338
+
339
+
### Using the `data` prop
340
+
341
+
The simplest approach, as shown in the basic example, is to provide data directly via the `data` prop of `<DataTable>`:
342
+
343
+
```tsx
344
+
<DataTabledata={products}>{/* ... */}</DataTable>
345
+
```
346
+
347
+
This works well for static data or when the data is already available in the component's scope.
348
+
349
+
### Using Content Context
350
+
351
+
You can also provide data via content context using `<ContentProvider>` from `@ctablex/core`:
352
+
353
+
```tsx
354
+
import { ContentProvider } from'@ctablex/core';
355
+
356
+
<ContentProvidervalue={products}>
357
+
<DataTable>{/* Children */}</DataTable>
358
+
</ContentProvider>;
359
+
```
360
+
361
+
This is useful when you want to share data between multiple components or when data is provided by a parent component.
362
+
363
+
### Using Data Provider Components
364
+
365
+
The recommended pattern for production applications is to provide data via content context in a dedicated data provider component. This component can fetch data, manage loading states, or handle reactive updates internally, then provide the data via content context. For example:
366
+
367
+
```tsx
368
+
<UserDataProvider>
369
+
<DataTable>{/* Children */}</DataTable>
370
+
</UserDataProvider>
371
+
```
372
+
373
+
`<UserDataProvider />` fetches user data and provides it via content context. `<DataTable>` consumes this data without needing a `data` prop. This approach keeps the component tree constant, as no data prop is passed down, which can improve performance and simplify component composition. It also promotes separation of concerns—data fetching logic stays in the provider, while presentation logic stays in the table components.
374
+
334
375
## Customization
335
376
336
377
### Custom Cell Content
337
378
338
-
You can customize the content of each cell by providing your own children to the `Column` component. For example, to format the price with a dollar sign:
379
+
You can customize the content of each cell by providing your own children to the `Column` component. For example, to format the price and add a suffix:
339
380
340
381
```tsx
341
382
<DataTabledata={products}>
@@ -458,11 +499,9 @@ Or render a special row:
458
499
<Table>
459
500
<TableHeader />
460
501
<TableBody>
461
-
<Row>
462
-
<tr>
463
-
<tdcolSpan={2}>Special Row</td>
464
-
</tr>
465
-
</Row>
502
+
<tr>
503
+
<tdcolSpan={2}>Special Row</td>
504
+
</tr>
466
505
{/* default rows */}
467
506
<Rows />
468
507
</TableBody>
@@ -632,6 +671,7 @@ That's the tour! You've seen how `@ctablex/table` works from the ground up:
632
671
633
672
-**Step-by-step transformation**: How `<Table />` expands into headers, rows, and cells through default children
634
673
-**The micro-context magic**: Data and column definitions flow through context, so you're not passing props everywhere
674
+
-**Three data providing patterns**: Via `data` prop, content context, or dedicated data provider components
635
675
-**Customization levels**: From dropping in a custom content component to completely rebuilding the table structure
636
676
-**Type safety**: Generic types on `<Column>` give you autocomplete and type checking for nested paths
0 commit comments