a workaround for fixing the _ module missing

This commit is contained in:
AllenFang 2018-07-14 17:04:35 +08:00
parent ec77a0539d
commit fadbcdaa24
5 changed files with 25 additions and 4 deletions

View File

@ -40,18 +40,33 @@ class ToolkitProvider extends statelessDrcorator(React.Component) {
this.state = {
searchText: ''
};
this._ = null;
this.onSearch = this.onSearch.bind(this);
this.setDependencyModules = this.setDependencyModules.bind(this);
}
onSearch(searchText) {
this.setState({ searchText });
}
/**
*
* @param {*} _
* this function will be called only one time when table render
* react-bootstrap-table-next/src/context/index.js will call this cb for passing the _ module
* Please consider to extract a common module to handle _ module.
* this is just a quick fix
*/
setDependencyModules(_) {
this._ = _;
}
render() {
const baseProps = {
keyField: this.props.keyField,
columns: this.props.columns,
data: this.props.data
data: this.props.data,
setDependencyModules: this.setDependencyModules
};
if (this.props.search) {
baseProps.search = {

View File

@ -19,6 +19,7 @@ export const getMetaInfo = columns =>
export const transform = (
data,
meta,
getValue,
{
separator,
ignoreHeader
@ -36,7 +37,7 @@ export const transform = (
content += data
.map((row, rowIndex) =>
visibleColumns.map((m) => {
let cellContent = row[m.field];
let cellContent = getValue(row, m.field);
if (m.formatter) {
cellContent = m.formatter(cellContent, row, rowIndex, m.formatExtraData);
}

View File

@ -18,7 +18,7 @@ export default Base =>
...csvDefaultOptions,
...exportCSV
};
const content = transform(data, meta, options);
const content = transform(data, meta, this._.get, options);
save(content, options);
}
};

View File

@ -179,7 +179,8 @@ BootstrapTable.propTypes = {
search: PropTypes.shape({
searchText: PropTypes.string,
searchContext: PropTypes.func
})
}),
setDependencyModules: PropTypes.func
};
BootstrapTable.defaultProps = {

View File

@ -47,6 +47,10 @@ const withContext = Base =>
this.SearchContext = props.search.searchContext(
_, this.isRemoteSearch, this.handleRemoteSearchChange);
}
if (props.setDependencyModules) {
props.setDependencyModules(_);
}
}
renderBase() {