Merge branch 'master'
[arvados-workbench2.git] / src / components / data-table / data-table.tsx
index ec260e967b02afbc03797d3e235a412610ff427f..43efdd0ada3bc97c50284926a3b75758375fb2c8 100644 (file)
@@ -3,12 +3,14 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { Table, TableBody, TableRow, TableCell, TableHead, StyleRulesCallback, Theme, WithStyles, withStyles, Typography } from '@material-ui/core';
+import { Table, TableBody, TableRow, TableCell, TableHead, TableSortLabel, StyleRulesCallback, Theme, WithStyles, withStyles, Typography } from '@material-ui/core';
 import { DataColumn } from './data-column';
 
+export type DataColumns<T> = Array<DataColumn<T>>;
+
 export interface DataTableProps<T> {
     items: T[];
-    columns: Array<DataColumn<T>>;
+    columns: DataColumns<T>;
     onRowClick?: (event: React.MouseEvent<HTMLTableRowElement>, item: T) => void;
     onRowContextMenu?: (event: React.MouseEvent<HTMLTableRowElement>, item: T) => void;
 }
@@ -23,9 +25,16 @@ class DataTable<T> extends React.Component<DataTableProps<T> & WithStyles<CssRul
                         <TableRow>
                             {columns
                                 .filter(column => column.selected)
-                                .map(({ name, renderHeader, key }, index) =>
+                                .map(({ name, renderHeader, key, sortDirection, onSortToggle }, index) =>
                                     <TableCell key={key || index}>
-                                        {renderHeader ? renderHeader() : name}
+                                        {renderHeader ?
+                                            renderHeader() :
+                                            <TableSortLabel
+                                                active={!!sortDirection}
+                                                direction={sortDirection}
+                                                onClick={() => onSortToggle && onSortToggle()}>
+                                                {name}
+                                            </TableSortLabel>}
                                     </TableCell>
                                 )}
                         </TableRow>
@@ -48,7 +57,7 @@ class DataTable<T> extends React.Component<DataTableProps<T> & WithStyles<CssRul
                                 </TableRow>
                             )}
                     </TableBody>
-                </Table> : <Typography 
+                </Table> : <Typography
                     className={classes.noItemsInfo}
                     variant="body2"
                     gutterBottom>