Skip to content

add custom column config #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions packages/iotex-react-block-producers/src/block-producers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import Avatar from "antd/lib/avatar";
import notification from "antd/lib/notification";
import Popover from "antd/lib/popover";
import Table from "antd/lib/table";
import Table, { ColumnProps } from "antd/lib/table";
import Column from "antd/lib/table/Column";
import { ApolloClient } from "apollo-client";
import gql from "graphql-tag";
// @ts-ignore
Expand Down Expand Up @@ -110,13 +111,23 @@ const Div: React.FunctionComponent<IProps> = ({ classes, children }) => (

const BpTableContainer = withStyles(styles)(Div);

interface ColumnMapItem extends ColumnProps<any> {
wrapRender?: (
renderRes: any,
text: any,
record: any,
index: number
) => JSX.Element;
}

type Props = {
extraColumns?: Array<object>;
extraMobileComponents?: Array<RenderDelegateComponent>;
apolloClient: ApolloClient<{}>;
badgeImg: string;
height?: string;
columnsTitleReplace?: Array<{ key: string; title: string }>;
columnsMap?: Record<string, ColumnMapItem>;
};

type State = {
Expand Down Expand Up @@ -161,7 +172,12 @@ export class BlockProducers extends Component<Props, State> {
}

public getColumns(): Array<object> {
const { badgeImg, extraColumns = [], columnsTitleReplace } = this.props;
const {
badgeImg,
extraColumns = [],
columnsTitleReplace,
columnsMap
} = this.props;
const columns: Array<{ [k: string]: any }> = [
{
title: t("candidates.rank"),
Expand Down Expand Up @@ -244,6 +260,24 @@ export class BlockProducers extends Component<Props, State> {
}
});
}
if (columnsMap) {
columns.forEach(column => {
if (columnsMap[column.dataIndex]) {
Object.assign(column, columnsMap[column.dataIndex]);
if (column.wrapRender) {
const render = column.render;
column.render = (text: any, record: any, index: number) => {
return column.wrapRender(
render && render(text, record, index),
text,
record,
index
);
};
}
}
});
}

return columns;
}
Expand Down