@@ -437,6 +437,105 @@ function FullDataTableExample() {
437437}
438438```
439439
440+ ### Data table with all of its elements, increased density, and zebra striping on data
441+
442+ Use as a broad example that includes most props available to data table.
443+
444+ ``` jsx
445+ function FullDataTableExample () {
446+ const [sortedRows , setSortedRows ] = useState (null );
447+
448+ const initiallySortedRows = [
449+ [
450+ < Link
451+ removeUnderline
452+ url= " https://www.example.com"
453+ key= " emerald-silk-gown"
454+ >
455+ Emerald Silk Gown
456+ < / Link> ,
457+ ' $875.00' ,
458+ 124689 ,
459+ 140 ,
460+ ' $121,500.00' ,
461+ ],
462+ [
463+ < Link
464+ removeUnderline
465+ url= " https://www.example.com"
466+ key= " mauve-cashmere-scarf"
467+ >
468+ Mauve Cashmere Scarf
469+ < / Link> ,
470+ ' $230.00' ,
471+ 124533 ,
472+ 83 ,
473+ ' $19,090.00' ,
474+ ],
475+ [
476+ < Link
477+ removeUnderline
478+ url= " https://www.example.com"
479+ key= " navy-merino-wool"
480+ >
481+ Navy Merino Wool Blazer with khaki chinos and yellow belt
482+ < / Link> ,
483+ ' $445.00' ,
484+ 124518 ,
485+ 32 ,
486+ ' $14,240.00' ,
487+ ],
488+ ];
489+
490+ const rows = sortedRows ? sortedRows : initiallySortedRows;
491+ const handleSort = useCallback (
492+ (index , direction ) => setSortedRows (sortCurrency (rows, index, direction)),
493+ [rows],
494+ );
495+
496+ return (
497+ < Page title= " Sales by product" >
498+ < Card>
499+ < DataTable
500+ columnContentTypes= {[
501+ ' text' ,
502+ ' numeric' ,
503+ ' numeric' ,
504+ ' numeric' ,
505+ ' numeric' ,
506+ ]}
507+ headings= {[
508+ ' Product' ,
509+ ' Price' ,
510+ ' SKU Number' ,
511+ ' Net quantity' ,
512+ ' Net sales' ,
513+ ]}
514+ rows= {rows}
515+ totals= {[' ' , ' ' , ' ' , 255 , ' $155,830.00' ]}
516+ sortable= {[false , true , false , false , true ]}
517+ defaultSortDirection= " descending"
518+ initialSortColumnIndex= {4 }
519+ onSort= {handleSort}
520+ footerContent= {` Showing ${ rows .length } of ${ rows .length } results` }
521+ hasZebraStripingOnData
522+ increasedTableDensity
523+ / >
524+ < / Card>
525+ < / Page>
526+ );
527+
528+ function sortCurrency (rows , index , direction ) {
529+ return [... rows].sort ((rowA , rowB ) => {
530+ const amountA = parseFloat (rowA[index].substring (1 ));
531+ const amountB = parseFloat (rowB[index].substring (1 ));
532+
533+ return direction === ' descending' ? amountB - amountA : amountA - amountB;
534+ });
535+ }
536+ }
537+ ```
538+
440539---
441540
442541## Best practices
0 commit comments