mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-28 13:10:03 +00:00
fix #510
This commit is contained in:
@@ -123,4 +123,7 @@ Default is `false`. Give true to avoid to attach the csv header.
|
||||
Default is `true`.
|
||||
|
||||
#### exportAll - [bool]
|
||||
Default is `true`. `false` will only export current data which display on table.
|
||||
Default is `true`. `false` will only export current data which display on table.
|
||||
|
||||
#### onlyExportSelection - [bool]
|
||||
Default is `false`. `true` will only export the data which is selected.
|
||||
@@ -26,7 +26,9 @@ class ToolkitProvider extends statelessDrcorator(React.Component) {
|
||||
fileName: PropTypes.string,
|
||||
separator: PropTypes.string,
|
||||
ignoreHeader: PropTypes.bool,
|
||||
noAutoBOM: PropTypes.bool
|
||||
noAutoBOM: PropTypes.bool,
|
||||
exportAll: PropTypes.bool,
|
||||
onlyExportSelection: PropTypes.bool
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ const ExportCSVButton = (props) => {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={ onExport }
|
||||
onClick={ () => onExport() }
|
||||
{ ...rest }
|
||||
>
|
||||
{ children }
|
||||
|
||||
@@ -5,13 +5,14 @@ const csvDefaultOptions = {
|
||||
separator: ',',
|
||||
ignoreHeader: false,
|
||||
noAutoBOM: true,
|
||||
exportAll: true
|
||||
exportAll: true,
|
||||
onlyExportSelection: false
|
||||
};
|
||||
|
||||
export default Base =>
|
||||
class CSVOperation extends Base {
|
||||
handleExportCSV = () => {
|
||||
const { columns, exportCSV } = this.props;
|
||||
handleExportCSV = (source) => {
|
||||
const { columns, exportCSV, keyField } = this.props;
|
||||
const meta = getMetaInfo(columns);
|
||||
const options = exportCSV === true ?
|
||||
csvDefaultOptions :
|
||||
@@ -20,7 +21,19 @@ export default Base =>
|
||||
...exportCSV
|
||||
};
|
||||
|
||||
const data = options.exportAll ? this.props.data : this.getData();
|
||||
// get data for csv export
|
||||
let data;
|
||||
if (typeof source !== 'undefined') {
|
||||
data = source;
|
||||
} else {
|
||||
data = options.exportAll ? this.props.data : this.getData();
|
||||
}
|
||||
|
||||
// filter data
|
||||
if (options.onlyExportSelection) {
|
||||
const selections = this.getSelected();
|
||||
data = data.filter(row => !!selections.find(sel => row[keyField] === sel));
|
||||
}
|
||||
const content = transform(data, meta, this._.get, options);
|
||||
save(content, options);
|
||||
}
|
||||
|
||||
@@ -269,8 +269,9 @@ const withContext = Base =>
|
||||
}
|
||||
|
||||
render() {
|
||||
const { keyField, columns, bootstrap4 } = this.props;
|
||||
const { keyField, columns, bootstrap4, registerExposedAPI } = this.props;
|
||||
const baseProps = { keyField, columns };
|
||||
if (registerExposedAPI) baseProps.registerExposedAPI = registerExposedAPI;
|
||||
|
||||
let base = this.renderBase();
|
||||
|
||||
|
||||
@@ -15,6 +15,14 @@ export default (
|
||||
keyField: PropTypes.string.isRequired
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
if (props.registerExposedAPI) {
|
||||
const getSelected = () => this.getSelected();
|
||||
props.registerExposedAPI(getSelected);
|
||||
}
|
||||
}
|
||||
|
||||
state = { selected: (this.props.selectRow && this.props.selectRow.selected) || [] };
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
@@ -25,6 +33,11 @@ export default (
|
||||
}
|
||||
}
|
||||
|
||||
// exposed API
|
||||
getSelected() {
|
||||
return this.state.selected;
|
||||
}
|
||||
|
||||
handleRowSelect = (rowKey, checked, rowIndex, e) => {
|
||||
const { data, keyField, selectRow: { mode, onSelect } } = this.props;
|
||||
const { ROW_SELECT_SINGLE } = Const;
|
||||
|
||||
Reference in New Issue
Block a user