mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
parent
586acaed68
commit
1f51f1a08d
@ -120,4 +120,7 @@ Custom the csv file separator.
|
||||
Default is `false`. Give true to avoid to attach the csv header.
|
||||
|
||||
#### noAutoBOM - [bool]
|
||||
Default is `true`.
|
||||
Default is `true`.
|
||||
|
||||
#### exportAll - [bool]
|
||||
Default is `true`. `false` will only export current data which display on table.
|
||||
@ -69,7 +69,8 @@ class ToolkitProvider extends statelessDrcorator(React.Component) {
|
||||
columns: this.props.columns,
|
||||
data: this.props.data,
|
||||
bootstrap4: this.props.bootstrap4,
|
||||
setDependencyModules: this.setDependencyModules
|
||||
setDependencyModules: this.setDependencyModules,
|
||||
registerExposedAPI: this.registerExposedAPI
|
||||
};
|
||||
if (this.props.search) {
|
||||
baseProps.search = {
|
||||
|
||||
@ -4,13 +4,14 @@ const csvDefaultOptions = {
|
||||
fileName: 'spreadsheet.csv',
|
||||
separator: ',',
|
||||
ignoreHeader: false,
|
||||
noAutoBOM: true
|
||||
noAutoBOM: true,
|
||||
exportAll: true
|
||||
};
|
||||
|
||||
export default Base =>
|
||||
class CSVOperation extends Base {
|
||||
handleExportCSV = () => {
|
||||
const { columns, data, exportCSV } = this.props;
|
||||
const { columns, exportCSV } = this.props;
|
||||
const meta = getMetaInfo(columns);
|
||||
const options = exportCSV === true ?
|
||||
csvDefaultOptions :
|
||||
@ -18,6 +19,8 @@ export default Base =>
|
||||
...csvDefaultOptions,
|
||||
...exportCSV
|
||||
};
|
||||
|
||||
const data = options.exportAll ? this.props.data : this.getData();
|
||||
const content = transform(data, meta, this._.get, options);
|
||||
save(content, options);
|
||||
}
|
||||
|
||||
@ -1,4 +1,10 @@
|
||||
import Operation from './src/op';
|
||||
|
||||
export default Base =>
|
||||
class StatelessOperation extends Operation.csvOperation(Base) {};
|
||||
class StatelessOperation extends Operation.csvOperation(Base) {
|
||||
registerExposedAPI = (...exposedFuncs) => {
|
||||
exposedFuncs.forEach((func) => {
|
||||
this[func.name] = func;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -15,6 +15,15 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.validateProps();
|
||||
if (props.registerExposedAPI) {
|
||||
const getData = () => this.getData();
|
||||
props.registerExposedAPI(getData);
|
||||
}
|
||||
}
|
||||
|
||||
// Exposed APIs
|
||||
getData = () => {
|
||||
return this.props.data;
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@ -46,6 +46,40 @@ describe('BootstrapTable', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getData', () => {
|
||||
let instance;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(
|
||||
<BootstrapTable keyField="id" columns={ columns } data={ data } />);
|
||||
instance = wrapper.instance();
|
||||
});
|
||||
|
||||
it('should return props.data', () => {
|
||||
expect(instance.getData()).toEqual(data);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when props.registerExposedAPI is defined', () => {
|
||||
const registerExposedAPI = jest.fn();
|
||||
beforeEach(() => {
|
||||
registerExposedAPI.mockClear();
|
||||
wrapper = shallow(
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
columns={ columns }
|
||||
data={ data }
|
||||
registerExposedAPI={ registerExposedAPI }
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
it('should call props.registerExposedAPI correctly', () => {
|
||||
expect(registerExposedAPI).toHaveBeenCalledTimes(1);
|
||||
expect(registerExposedAPI.mock.calls[0][0].name).toEqual('getData');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when props.classes was defined', () => {
|
||||
const classes = 'foo';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user