Print options with Pagination

Community plugins and extensions
Post Reply
User avatar
kevinvdheuvel
Posts: 96
Joined: Mon Mar 09, 2015 3:31 pm

Print options with Pagination

Post by kevinvdheuvel »

Hi

We have a requirement like need to print all the pages, we are using a scheduler with pagination. While implementing the print option, we are able to print single page instead of total pages and we tried with setting the pagination option to Multiple pages (in Print plugin) but it is generating blank pages after the first page.

Do we have any way to implement this requirement?

User avatar
pmiklashevich
Core Developer
Core Developer
Posts: 2996
Joined: Fri Apr 01, 2016 11:08 am

Re: Print options with Pagination

Post by pmiklashevich »

Export plugin docs say "Note that the export feature is currently not supported if your store is buffered." Docs for Printable plugin doesn't say that directly, but Printable plugin extends Export plugin. Both plugins work with the data in the store, so if the pagination enabled and only 1-50 records out of 500 are in the store, the plugin will print/export that 50 records. And the configuration field in print/export dialog looks a bit confusing since it's called "Control pagination". But this config is only about how to display the current data. Therefore the plugin doesn't support pagination. So if you want to print all the data, you need to load it to the store.

P.S. I've updated Sch.plugin.Printable docs, so they mention the note too:
Note that the print feature is currently not supported if your store is buffered.
If you want to use our solution for export, please load all the data to the store. Actually any client-side solution will require to load data to the client first, otherwise exporter couldn't know what should be exported.

As a workaround you can save your pagination settings, on beforeexport load all data, on load print the data, on afterexport set the pagination settings back and reload the store. But I'm not sure about the performance. Might take some time for loading-exporting-reloading.
Pavel Miklashevich - Core Developer

User avatar
kevinvdheuvel
Posts: 96
Joined: Mon Mar 09, 2015 3:31 pm

Re: Print options with Pagination

Post by kevinvdheuvel »

Hi
we had tried with setting pagination size with total count and reloading the store. But we are unable to view all the data in PDF.

Code: Select all

plugins : [ 
                               
                                Ext.create('Sch.plugin.Printable',{
                                    ptype              : 'scheduler_printable',
                                    pluginId           : 'printable',
                                    exportDialogConfig : {
                                        format           : "A3",
                                        orientation      : "landscape",
                                        range            : "complete",
                                        showHeader       : true,
                                        stateful             : true,
                                        showColumnPicker     : true,
                                        modal                : true
                                    },
                                    docType             : '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">',
                                    autoPrintAndClose   : true,
                                   
                                    afterPrint : function (scheduler) {
                                        var store= Ext.getCmp("schedulergrid").getResourceStore();
                                        store.pageSize=Scheduler.paginationSize;
                                        store.reload();
                                    },
                                    listeners          : {
                                        beforeexport : function (scheduler, exporter, config) {
											//	Scheduler.paginationSize is global variable to store the pageSize
                                            Scheduler.paginationSize=scheduler.getResourceStore().pageSize;
                                            scheduler.getResourceStore().pageSize= scheduler.getResourceStore().totalCount;
                                            scheduler.getResourceStore().reload();
                                        }
                                        
                                    }
                                    
                                })
                           ]


Do we miss anything?

User avatar
pmiklashevich
Core Developer
Core Developer
Posts: 2996
Joined: Fri Apr 01, 2016 11:08 am

Re: Print options with Pagination

Post by pmiklashevich »

The idea is to return false from the beforeexport handler. It pauses export. Then need or cancel export or continue it. Load is async process, so you need to subscribe on load event and then decide what to do. And afterexport handler will let you know when export is finished and you can reload your data again.

Please try something like this:

Code: Select all

plugins : [{
    ptype     : 'scheduler_printable',
    listeners : {
        beforeexport : function (scheduler, exporter, config) {
            var plugin         = this,
                continueExport = function () {
                    plugin.myBeforeExport();

                    exporter.extractPages(scheduler, config, function (pages) {
                        plugin.onPagesExtracted(pages, scheduler, exporter, config);
                    }, plugin);
                },
                cancelExport   = function () {
                    // Stop any ongoing export operation
                    plugin.cancelExport();

                    // Close export dialog if needed
                    var dialog = plugin.getActiveExportDialog();
                    dialog && dialog.destroy();
                },
                eventStore     = scheduler.getEventStore(),
                // Save page sige and current page
                pageSize       = eventStore.getPageSize(),
                currentPage    = eventStore.currentPage;

            // Setup listener on store load
            eventStore.on({
                load   : function (store, records, successful, operation) {
                    // Load is finished successfully, so we may continue export
                    if (successful) {
                        // At the end need to restore the paging
                        plugin.on({
                            afterexport : function () {
                                eventStore.setPageSize(pageSize);
                                eventStore.loadPage(currentPage);
                            },
                            single      : true // The listener is called once and gets auto destroyed
                        });

                        continueExport();
                    }
                    // Load is not finished successfully, so need to cancel export
                    else {
                        cancelExport();
                    }
                },
                single : true // The listener is called once and gets auto destroyed
            });

            // When pageSize is 0 paging is disabled
            eventStore.setPageSize(0);

            // Reload the store
            eventStore.load();

            // Prevent export (pause it)
            return false;
        }
    }
}]
Pavel Miklashevich - Core Developer

User avatar
kevinvdheuvel
Posts: 96
Joined: Mon Mar 09, 2015 3:31 pm

Re: Print options with Pagination

Post by kevinvdheuvel »

Thanks very much

Post Reply