<div class="wrap">
    <h1 class="wp-heading-inline"><?php echo esc_html(__('Invoices', 'salesloo')); ?> <button id="export-invoices" class="button">Export to CSV</button></h1>

    <hr class="wp-header-end">

    <form method="get" action="">
        <input type="hidden" name="page" value="salesloo-invoice" />
        <?php $list_table->views(); ?>
        <?php $list_table->search_box(__('Search Invoice', 'salesloo'), 'salesloo-button'); ?>
        <?php $list_table->display(); ?>
    </form>
</div>
<script>
    jQuery('#export-invoices').on('click', function() {
        jQuery(this).html('Proses..');

        jQuery.ajax({
            type: "POST",
            url: '<?php echo admin_url('admin-ajax.php'); ?>',
            dataType: "json",
            data: {
                action: 'export-invoices',
                nonce: '<?php echo wp_create_nonce('salesloo'); ?>'
            },
            success: function(data) {
                console.log(data);
                jQuery('#export-invoices').html('Export To Excel');
                window.open(data.url, '_blank');
            }
        });
    })
</script>