import * as React from 'react'; import * as classNames from 'classnames'; import {CSSProperties, SFC, HTMLProps, Ref} from 'react'; import {Icon, Scrollbars} from './../'; import {ColumnHeaderProperty, SortProperty} from './models'; import {getSortProperty, isSortDescending} from './utils/string'; export interface TableProps extends HTMLProps { properties: ColumnHeaderProperty[]; sort: string; tableMinWidth: number; onSort: (property: string) => void; } let scrollbars: Scrollbars; export const DatagridTable: SFC = (props: TableProps) => { const {children, tableMinWidth} = props; const style = {minWidth: tableMinWidth}; return (
{renderHeaders(props)}
{children}
); }; DatagridTable.displayName = 'DatagridTable'; const renderHeaders = (props: TableProps) => { const {properties, sort} = props; return properties.map((p, index) => (
{p.name} {p.sortKey && }
)); }; const handleSortInfo = (props: TableProps, columnPropertyKey: string) => () => { if (!columnPropertyKey) { return; } const hasToSortSameColumn = getSortProperty(props.sort) === columnPropertyKey; if (hasToSortSameColumn) { props.onSort(invertSortingDirection(props.sort)); return; } props.onSort(columnPropertyKey); }; const invertSortingDirection = (property: string) => { return isSortDescending(property) ? property.substr(1) : `-${property}`; };