Skip to content

Commit 89df976

Browse files
Merge pull request #5939 from SelenaAungst/LPD-47018-2
docs(@clayui/table): Add code example of table-nested-rows
2 parents 1df746f + 534b60f commit 89df976

File tree

2 files changed

+517
-18
lines changed

2 files changed

+517
-18
lines changed

packages/clay-core/docs/table.mdx

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,22 @@ It is also possible to implement your own logic on the client side when your dat
237237
</code> API defined.
238238
</div>
239239

240-
```jsx
241-
export function App() {
242-
const [sort, setSort] = (useState < Sorting) | (null > null);
240+
```jsx preview
241+
import React, {useMemo, useState} from 'react';
242+
import {Body, Cell, Text, Head, Row, Table, Provider} from '@clayui/core';
243+
244+
import '@clayui/css/lib/css/atlas.css';
245+
246+
export default function App() {
247+
const [sort, setSort] = useState(null);
243248
const [items, setItems] = useState([
244249
{files: 22, id: 1, name: 'Games', type: 'File folder'},
245250
{files: 7, id: 2, name: 'Program Files', type: 'File folder'},
246251
]);
247252

248253
const filteredItems = useMemo(() => {
249254
if (!sort) {
250-
return;
255+
return items;
251256
}
252257

253258
return items.sort((a, b) => {
@@ -265,21 +270,37 @@ export function App() {
265270
}, [sort, items]);
266271

267272
return (
268-
<Table onSortChange={setSort} sort={sort}>
269-
<Head>
270-
<Cell key="name" sortable>
271-
Name
272-
</Cell>
273-
<Cell key="files" sortable>
274-
Files
275-
</Cell>
276-
<Cell key="type" sortable>
277-
Type
278-
</Cell>
279-
</Head>
273+
<Provider spritemap="/public/icons.svg">
274+
<div className="p-4">
275+
<Table onSortChange={setSort} sort={sort}>
276+
<Head>
277+
<Cell key="name" sortable>
278+
Name
279+
</Cell>
280+
<Cell key="files" sortable>
281+
Files
282+
</Cell>
283+
<Cell key="type" sortable>
284+
Type
285+
</Cell>
286+
</Head>
280287

281-
<Body defaultItems={filteredItems}>...</Body>
282-
</Table>
288+
<Body defaultItems={filteredItems}>
289+
{(row) => (
290+
<Row>
291+
<Cell>
292+
<Text size={3} weight="semi-bold">
293+
{row['name']}
294+
</Text>
295+
</Cell>
296+
<Cell>{row['files']}</Cell>
297+
<Cell>{row['type']}</Cell>
298+
</Row>
299+
)}
300+
</Body>
301+
</Table>
302+
</div>
303+
</Provider>
283304
);
284305
}
285306
```

0 commit comments

Comments
 (0)