snapshift / Ext.ux.grid.Printer

An Extjs 5/6/7 Component to print grid content
6 stars 5 forks source link
extjs extjs6 extjs7

Overview

Ext.ux.grid.Printer is a Extjs library that provides a way of printing Ext Grid Component (see what is Extjs there). It's a fork of https://github.com/loiane/extjs4-ux-gridprinter which is no more maintained.

This component is used in Arhia applications and we aim to maintain it.

It's currently used in production with ExtJS Classic 7.5.0

We are open to PR, if you want to contribute & send a PR, please :

Installation

Place the folder ux/grid in your project.

Usage

It's a helper class to easily print the contents of a ExtJS grid.
It will open a new window with a table where the first row contains the headings from your column model, and with a row for each item in your grid's store.
When formatted with appropriate CSS it should look very similar to a default grid. If renderers are specified in your column model, they will be used in creating the table. Override headerTpl and bodyTpl to change how the markup is generate.

In your application file, add:

Ext.Loader.setConfig({enabled: true});

Ext.require([
    'Ext.ux.grid.Printer',
]);

Ext.ux.grid.Printer.print just take a single argument - a normal grid instance. Use it like this:

var myGrid = new Ext.grid.GridPanel({
  //your usual grid config here
});

Ext.ux.grid.Printer.print(myGrid);

Example : https://fiddle.sencha.com/#view/editor&fiddle/1rge

Options

You need to set the custom config before calling Ext.ux.grid.Printer.print function.

You can customize some options to:

   Ext.ux.grid.Printer.pageTitle = title;
Ext.ux.grid.Printer.printLinkText = "Imprimer";
Ext.ux.grid.Printer.closeLinkText = "Fermer";
Ext.ux.grid.Printer.printAutomatically = false;
Ext.ux.grid.Printer.stylesheetPath = '/some/other/path/gridPrint.css';
Ext.ux.grid.Printer.hideExpandedRow = true;
  Ext.ux.grid.Printer.headerContent = `Hey nice report`;
 Ext.ux.grid.Printer.headExtra = `
        <link
            href="https://fonts.googleapis.com/css?family=Dosis:400,500,600,700,800|Nunito:400,400i,600,600i,700,700i|Roboto:400,400i,500,500i,700,700i"
            rel="stylesheet">
        `;     

ECMAScript version

This library is only written in ES5 (eg no const, let...) so need to transpile it for (very) old browsers, but of course it's up to you to include it in your tool chain/bundler.