Show modal once draw is completed

Show modal once draw is completed

RedfishRedfish Posts: 5Questions: 2Answers: 0

I am using serverside processing with the processing message. This is working great. I have created a modal pop up that lets the user choose which columns to export to CSV. However, since it is serverside the export to CSV only will push out the visible rows. To get around this the user can just set to all rows and export, switch back to the number of rows they were viewing. As we have a large dataset limiting the viewed rows makes the response better.

So I am setting it up so when the user clicks on the export button, we resize the table to the amount of rows based on their current search criteria, page.info().recordsDisplay and draw. Since we have the server processing message, I want to know when this draw is completed, then show perform the modal('show') event. Not sure how to verify when the draw is done. This will not happen on EVERY draw of the table, only when the export button is hit, so I don't think I can use a drawcallback.

This is the code I am using when the export button is hit. headers are captured for later csv export. Currently I use a timeout function on the modal display, but this is not reliable.

        var tableHeaders = [];
        var table = $('#magic_panel').DataTable().columns().every( function () {
            tableHeaders.push( $(this.header()).text() );
        });
        var pageLength = table.page.info().length;
        table.context['0']._iDisplayLength = table.page.info().recordsDisplay;
        table.draw();

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 4,630Questions: 0Answers: 814

    Hi @Redfish ,

    You can use the draw, this is triggered after a draw has completed.

    Cheers,

    Colin

  • RedfishRedfish Posts: 5Questions: 2Answers: 0

    The problem with that, is that EVERY draw function will perform the action. so showing a modal as part of the action will show on every table draw. I just want the modal to show once THAT draw is completed. Once the modal is closed the table is resized back to original page length and draw. So that creates a loop.

  • colincolin Posts: 4,630Questions: 0Answers: 814
    Answer ✓

    You can use one to listen to that draw just the once, or you can call off() to stop listening to it. If that doesn't work, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • RedfishRedfish Posts: 5Questions: 2Answers: 0

    Colin thanks a bunch. I was able to use the one option to get what I needed. Appreciate the help.

Sign In or Register to comment.