@@ -237,17 +237,22 @@ It is also possible to implement your own logic on the client side when your dat
237
237
</code > API defined.
238
238
</div >
239
239
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 );
243
248
const [items , setItems ] = useState ([
244
249
{files: 22 , id: 1 , name: ' Games' , type: ' File folder' },
245
250
{files: 7 , id: 2 , name: ' Program Files' , type: ' File folder' },
246
251
]);
247
252
248
253
const filteredItems = useMemo (() => {
249
254
if (! sort) {
250
- return ;
255
+ return items ;
251
256
}
252
257
253
258
return items .sort ((a , b ) => {
@@ -265,21 +270,37 @@ export function App() {
265
270
}, [sort, items]);
266
271
267
272
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>
280
287
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>
283
304
);
284
305
}
285
306
```
0 commit comments