Giter VIP home page Giter VIP logo

tests's People

Contributors

novsstation avatar

Watchers

 avatar

tests's Issues

2

โš ๏ธ The information contained within this page details our current vision of a feature/product design and is subject to change. You should not use this information in your production environment. We consider any feedback you share with us, but you should not expect it to be reflected in the final implementation. .


The Problem

The DevExtreme DataGrid does not allow users to export grid data to PDF documents.

The Proposed Solution

We plan to integrate the third-party jsPDF library and the jsPDF-AutoTable plugin into the DataGrid API and enhance our exportDataGrid method to support export as a PDF.

The proposed solution allows for the following customizations:

  • Cell content
  • Addition of page headers and footers
  • Inclusion of custom content alongside the grid
  • Export of multiple grids into a one page PDF
  • Export of multiple grids into a multiple-page PDF

The export of the DataGrid with a custom color scheme is not currently supported.

The resulting PDFs will retain DataGrid settings such as grouping, bands, summaries, etc.

Implementation Details

The exportDataGrid method accepts the following object:

exportDataGrid({
    component: DataGrid, // A DataGrid instance
    pdfDoc: Object, // A jsPDF instance
    customizeCell: Function, // Customizes a grid cell
    autoTableOptions: Object // Configures the AutoTable plugin
});

Use Cases

Export DataGrid as is

const dataGridOptions = {
    onExporting: e => {
        const pdfDoc = new jsPDF('p', 'pt', 'a4');
        const options = {
            pdfDoc: pdfDoc,
            component: e.component
        };

        exportDataGrid(options).then(() => {
            pdfDoc.save('filePDF.pdf');
        });

        e.cancel = true;
    } 
};

GitHub Logo

Customize cell content

const dataGridOptions = {
    onExporting: e => {
        const pdfDoc = new jsPDF('p', 'pt', 'a4');
        const options = {
            pdfDoc: pdfDoc,
            component: e.component,
            customizeCell: (pdfCell, gridCell) => {
                if(gridCell.column.dataField === 'Picture') {
                    if(gridCell.rowType === 'data') {
                        pdfCell.content = '';
                        pdfCell.customDrawCell = (data) => {
                            pdfDoc.addImage(imageData, 'PNG', data.cell.x, data.cell.y, 50, 70);
                        };
                    }
                }
            }
        };

        exportDataGrid(options).then(() => {
	        pdfDoc.save('filePDF.pdf');
        });

        e.cancel = true;
    } 
};

GitHub Logo

Add header and footer

const buttonOptions = {
    text: 'Export Grids',
    onClick: () => {
        const pdfDoc = new jsPDF('p', 'pt', 'a4');
        const options = {
            pdfDoc: pdfDoc,
            component: dataGrid
        };

        exportDataGrid(options).then(() => {
            pdfDoc.setFontSize(12);
            const pageCount = pdfDoc.internal.getNumberOfPages();
            for (let i = 1; i <= pageCount; i++) {
                pdfDoc.setPage(i);
                const pageSize = pdfDoc.internal.pageSize;
                const pageWidth = pageSize.width ? pageSize.width : pageSize.getWidth();
                const pageHeight = pageSize.height ? pageSize.height : pageSize.getHeight();
                const header = 'Report 2014';
                const footer = `Page ${i} of ${pageCount}`;

                // Header
                pdfDoc.text(header, 40, 15, { baseline: 'top' });

                // Footer
                pdfDoc.text(footer, pageWidth / 2 - (pdfDoc.getTextWidth(footer) / 2), pageHeight - 15, { baseline: 'bottom' });
            }
        }).then(() => {
            pdfDoc.save('filePDF.pdf');
        });
    }
};

Watch the video

Include custom content alongside the grid

const buttonOptions = {
    text: 'Export Grids',
    onClick: () => {
        const pdfDoc = new jsPDF('p', 'pt', 'a4');
        const options = {
            pdfDoc: pdfDoc,
            component: dataGrid,
            autoTableOptions: {
                margin: { top: 15, left: 15 },
                tableWidth: 310
            }
        };

        exportDataGrid(options).then(() => {
            pdfDoc.addImage(imageBase64, 340, 15);

            const pageSize = pdfDoc.internal.pageSize;
            const pageWidth = pageSize.width ? pageSize.width : pageSize.getWidth();

            pdfDoc.setFontSize(10);
            pdfDoc.text(custom_text, 340, 96, {
                maxWidth: pageWidth - 360,
                align: 'justify',
                lineHeightFactor: 1.6,
                baseline: 'top'
            });
        }).then(() => {
            pdfDoc.save('filePDF.pdf');
        });
    }
};

GitHub Logo

Try It

Live Sandboxes

  1. Export DataGrid as is
  2. Customize cell content
  3. Add page header and footer
  4. Include custom content alongside the grid
  5. Export multiple grids into one page of a PDF document
  6. Export multiple grids into different pages of a PDF document

Installation

Import exportDataGrid, jsPDF, and jsPDF-AutoTable.

We Need Your Feedback

Take a Quick Poll

Do you find export to PDF useful for your projects?

Get Notified of Updates

Subscribe to this thread or to our Facebook and Twitter accounts for updates on this topic.`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.