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

How to custom-refresh data onExport #7720

Open
hepcat72 opened this issue Feb 10, 2025 · 1 comment
Open

How to custom-refresh data onExport #7720

hepcat72 opened this issue Feb 10, 2025 · 1 comment
Labels
help-wanted Issues we need or would love help from the community to resolve.

Comments

@hepcat72
Copy link
Contributor

Description

I am not using the built-in server-side pagination, which is a separate issue^. I am using my own server-side pagination by sending queries to my Django view onSort, onSearch, and onColumnSearch, which uses the BST options (limit, offset, search, order, and sort [and some yet-to-be-developed column search params]) to retrieve a page's worth of a Django object_list QuerySet data for display.

I would like to add an onExport event code to grab all the JSON data for export. I.e. Let's say I would have 1000 pages, but the only data currently present is 10 rows worth. Since I'm not using the built-in server-side pagination, how can I retrieve that JSON data and make the export operate on it instead of on the data currently displayed in the django template? Is that possible?

I realized that if I used the same mechanism to retrieve the Django QuerySet object containing all of the data to populate the page, it would interrupt the export operation, though perhaps upon page load, I could call the export... (I'm still thinking this through.)

^ I want to use a django template to render the table rows, but when I use the built-in server-side pagination, it replaces my customized row template with the retrieved JSON data without all of the template decorations.

Example(s)

Image
@hepcat72 hepcat72 added the help-wanted Issues we need or would love help from the community to resolve. label Feb 10, 2025
@hepcat72
Copy link
Contributor Author

Here's my clunky work-around. Since I cannot get the clicked export type and trigger a full download after updating the page, I just have the user confirm their intent. If they want all data, they have to follow the instructions:

        function exportMessage() {
            if ({{ limit }} !== 0 && {{ limit }} !== {{ page_obj.paginator.object_list.count }}) {
                if (confirm("Download 1 page?\n\nTo retrieve all data, cancel and select 'ALL' from the rows per page select list below and try again.")) {
                    console.log("Downloading page {{ page_obj.number }}.");
                } else {
                    throw new Error("Canceling download");
                }
            }
        }

        document.addEventListener("DOMContentLoaded", function(){
            $('#file_list').bootstrapTable({
                onExportStarted: function (event) {
                    exportMessage();
                },
        });

I have to throw an error to cancel the download, since I can't seem to automatically load the full data by changing the URL.

Here's an example screenshot:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted Issues we need or would love help from the community to resolve.
Projects
None yet
Development

No branches or pull requests

1 participant