Skip to content

Instantly share code, notes, and snippets.

@sitch
Created October 25, 2018 05:27
Show Gist options
  • Select an option

  • Save sitch/19413a8f590ae70220fc47d4640a7b16 to your computer and use it in GitHub Desktop.

Select an option

Save sitch/19413a8f590ae70220fc47d4640a7b16 to your computer and use it in GitHub Desktop.
import React from "react"
import PropTypes from "prop-types"
import { connect } from "dva"
import { Form, Table } from "antd"
import { indicator, styles as tableStyles } from "dva-table-helpers"
// import { url } from "dva-route-helpers"
import classnames from "classnames"
import { EditableCell, EditableRow } from "dva-table-helpers"
import styles from "dva-table-helpers/EditableTable.less"
import all from "./columns/all"
import funder from "./columns/funder"
// const dataSource = [
// {
// term: 3,
// buy_rate: 1.16,
// commission: "10%",
// max_upsell: "18%",
// mpr: 8.5,
// },
// {
// term: 4,
// buy_rate: 1.16,
// commission: "10%",
// max_upsell: "18%",
// mpr: 8.5,
// },
// {
// term: 5,
// buy_rate: 1.16,
// commission: "10%",
// max_upsell: "18%",
// mpr: 8.5,
// },
// ]
//
const EditableFormRow = Form.create()(EditableRow)
class IndustryTableForm extends React.PureComponent {
state = {
sort: {
field: "naics_code",
order: "ascend",
// order: "descend",
},
}
render() {
const { industries, dataSource, loading, type } = this.props
const components = {
body: {
row: EditableFormRow,
cell: EditableCell,
},
}
const cols = (type === "all" ? all : funder)(this).map(col => {
if (!col.editable) {
return col
}
return {
...col,
onCell: record => ({
record,
editable: col.editable,
dataIndex: col.dataIndex,
title: col.title,
handleSave: this.handleSave,
}),
}
})
return (
<Table
rowKey="id"
size="small"
components={components}
className={classnames({
[tableStyles.table]: true,
})}
rowClassName={() => styles["editable-row"]}
loading={{ indicator, spinning: loading }}
// dataSource={dataSource}
dataSource={industries}
columns={cols}
// columns={columns(this)}
pagination={false}
expandIconAsCell={false}
/>
)
}
}
IndustryTableForm.propTypes = {
industries: PropTypes.array,
dataSource: PropTypes.array,
loading: PropTypes.bool,
type: PropTypes.oneOf(["all", "funder"]),
// section: PropTypes.oneOf(["pricing", "scoring", "triggers"]),
}
IndustryTableForm.defaultProps = {
industries: [],
dataSource: [],
loading: false,
type: "funder",
// section: "scoring",
}
export default connect(({ app }) => ({ app }))(IndustryTableForm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment