Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV export doesn't keep order #2580

Open
Jeehut opened this issue Mar 8, 2016 · 2 comments · May be fixed by #3575
Open

CSV export doesn't keep order #2580

Jeehut opened this issue Mar 8, 2016 · 2 comments · May be fixed by #3575

Comments

@Jeehut
Copy link

Jeehut commented Mar 8, 2016

I just came across the need to sort and filter data and export it as a CSV file. While filtering and exporting works just fine the order is reset to the default database order. It doesn't keep the order from the list view for exported data. Is this the expected behavior and if so, could we change this?

I hope I didn't miss something. Thanks in advance!

@Jeehut Jeehut changed the title Export doesn't keep order CSV-Export doesn't keep order Mar 8, 2016
@Jeehut Jeehut changed the title CSV-Export doesn't keep order CSV export doesn't keep order Mar 8, 2016
@silva96
Copy link

silva96 commented Sep 28, 2016

This happens to me also, I'm using version 0.6.0 though

@pcai
Copy link
Contributor

pcai commented Nov 21, 2022

I recently ran into this. The CSV row order is determined by the database primary key, as it uses find_each to avoid loading all records into memory simultaneously. see this code:

https://github.com/railsadminteam/rails_admin/blob/master/lib/rails_admin/support/csv_converter.rb#L74

Rails requires ordering by primary key for find_each, so it would be necessary to avoid using find_each in order to preserve sort order. However, this is a little tricky because we still want to avoid loading all records into memory to generate a CSV.

Some potential solutions may include rewriting to use a streaming SQL query, or using some form of pagination. This may expose performance problems as arbitrary sorting and filtering without indexes at large scale is problematic.

EDIT: here are some logs confirming the problem when exporting to CSV --
image

Without making any specific promises, I'm going to attempt to hack a solution this week.

@pcai pcai linked a pull request Nov 26, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants