// @flow import * as React from 'react'; import { Component, PropTypes } from '../../libs'; import { getValueByPath } from "./utils"; import Checkbox from '../checkbox'; import Tag from '../tag'; import type { TableFooterProps, _Column } from "./Types"; export default class TableFooter extends Component { isCellHidden(index: number, columns: Array<_Column>): boolean { const { fixed } = this.props; if (fixed === true || fixed === 'left') { return index >= this.leftFixedCount; } else if (fixed === 'right') { let before = 0; for (let i = 0; i < index; i++) { before += columns[i].colSpan; } return before < this.columnsCount - this.rightFixedCount; } else { return (index < this.leftFixedCount) || (index >= this.columnsCount - this.rightFixedCount); } } get columnsCount(): number { return this.props.tableStoreState.columns.length; } get leftFixedCount(): number { return this.props.tableStoreState.fixedColumns.length; } get rightFixedCount(): number { return this.props.tableStoreState.rightFixedColumns.length; } render() { const { tableStoreState, layout, fixed, summaryMethod, sumText } = this.props; const sums = summaryMethod ? summaryMethod(tableStoreState.columns, tableStoreState.data) : tableStoreState.columns.map((column, index) => { if (index === 0) { return sumText; } const result = tableStoreState.data.reduce((pre, data) => pre + parseFloat(getValueByPath(data, column.property)), 0); return isNaN(result) ? '' : result; }); return ( {tableStoreState.columns.map((column, index) => ( ))} {!fixed && ( )} {tableStoreState.columns.map((column, index) => ( ))} {!fixed && (
{sums[index]}
)}
); } }