novsstation / tests Goto Github PK
View Code? Open in Web Editor NEWtests
tests
The DevExtreme DataGrid does not allow users to export grid data to PDF documents.
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:
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.
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
});
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;
}
};
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;
}
};
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');
});
}
};
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');
});
}
};
Import exportDataGrid, jsPDF, and jsPDF-AutoTable.
Do you find export to PDF useful for your projects?
Subscribe to this thread or to our Facebook and Twitter accounts for updates on this topic.`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.