Can you export the csv after sorting the table and have the csv display the sorted table?
I want the data exported in the csv to be displayed the same way it is being displayed on the table.
For e.g. if I have sorted the table and the order changes, it should appear the same in the csv. Currently, when exporting, it takes the format as it was before sorting.
Is there a way to go around this?
Thanks.
@rhmmuh005 I will figure a way to achieve your requirement :)
I am having the same issue. I would be curious to see the result.
hey guys, try to add exportAll: false you may fix this issue.
exportAll: false-- I have used this but still not getting sorted CSV is there any way?
Hi @rhmmuh005,
I found a workaround which is pretty much straightforward.
Add this under
<ToolkitProvider
keyField="id"
data={data}
columns={columns}
search
exportCSV={{
fileName: `In-Active_Partner(s)_List_${new Date().getMonth() +
1}/${new Date().getDate()}/${new Date().getFullYear()}.csv`,
noAutoBOM: false,
}}
>
{(props) => (
<div>
<MyExportCSV {...props.csvProps} />
<div className="table-responsive-lg">
<BootstrapTable
ref={table}
{...props.baseProps}
/>
</div>
</div>
)}
</ToolkitProvider>
And MyExportCSV function looks like this :
const MyExportCSV = (props) => {
const handleClick = () => {
// passing my custom data
if (table.current.sortContext.state.sortOrder) {
props.onExport(table.current.paginationContext.props.data);
} else {
props.onExport();
}
};
return (
<ButtonIcon
size="sm"
icon="download"
className="ml-1 mt-lg-0 mb-2"
iconClassName="fs--2"
onClick={handleClick}
>
.CSV
</ButtonIcon>
);
};
Here, I have invoked onExport which with arguments takes that data for csv export. So, if statement will check between if it is sorted or not using table ref.
Let me know if it works for you! Peace out.