import {autobind} from "core-decorators"; import i18n from "i18next"; import {action, computed} from "mobx"; import {observer} from "mobx-react"; import * as React from "react"; import Button from "focus-components/button"; import {ListStore} from "../store"; import {ListStoreBase} from "../store-base"; import {LineProps} from "./line"; import {Table, TABLE_CELL_CLASS} from "./table"; export interface StoreTableProps { sortableColumns?: (keyof T)[]; store: ListStoreBase; } @autobind @observer export class StoreTable> extends Table> { @computed protected get data() { const data = this.props.data || (this.props.store as ListStore).dataList; if (!data) { throw new Error("`props.data` doit ĂȘtre renseignĂ© pour un usage avec un `SearchStore`"); } return data; } protected renderTableHeader() { const {columns, sortableColumns = [], store: {sortAsc, sortBy}} = this.props; return ( {Object.keys(columns).map(col => (
c === col) ? -3 : 0}}>
{i18n.t(columns[col])}
{sortableColumns.find(c => c === col) ?
: null}
))} ); } @action private sort(sortBy: string, sortAsc: boolean) { const {store} = this.props; store.sortAsc = sortAsc; store.sortBy = sortBy as keyof T; } }