Skip to content

Commit

Permalink
feat: table支持自定义render
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaMaid committed Nov 6, 2018
1 parent c71f0c3 commit 45463d2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions components/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

// tslint:disable no-any
import {Component} from 'react';
import * as React from 'react';
import * as classNames from 'classnames';
import {IBaseComponent} from '../template/component';

export interface ITableProps extends IBaseComponent {
// tslint:disable-next-line no-any
data: any[];
columns: IColumns[];
fixedTitle?: boolean;
Expand All @@ -21,6 +20,7 @@ export interface IColumns {
dataIndex: string;
fixed?: 'left' | 'right';
style?: React.CSSProperties;
render?: (v: any) => void;
}

export interface ITableState {
Expand Down Expand Up @@ -255,9 +255,14 @@ export class Table extends Component<ITableProps, ITableState> {
return (
<tr key={key}>
{
columns.map((column, index) => (
<td key={index}>{item[column.dataIndex]}</td>
))
columns.map((column, index) => {
const v = item[column.dataIndex];
return (
<td key={index}>
{column.render ? column.render(v) : v}
</td>
);
}
}
</tr>
);
Expand Down

0 comments on commit 45463d2

Please sign in to comment.