FlexGrid - Export 'Selected' rows
Export selected rows of a FlexGrid to a PDF document
by Troy Taylor
HTML
<script src="http://cdn.wijmo.com/5.20163.254/controls/wijmo.min.js"></script>
<link rel="stylesheet" href="http://cdn.wijmo.com/5.20163.254/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.20163.254/controls/wijmo.pdf.min.js"></script>
<script src="http://cdn.wijmo.com/5.20163.254/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.20163.254/controls/wijmo.grid.pdf.min.js"></script>
<h1>FlexGrid</h1>
<p>Check boxes in the Export Row column and click the 2nd button to export 'selected' rows to a PDF </p>
<div id="theGrid" style="width:100%;height:350px;"></div>
<br>
<br>
<input type="button" name="export" onclick="exportToPDF()" value="Export to PDF" />
<input type="button" name="export" onclick="exportSelectedRowsToPDF()" value="Export Selected Rows" />
<br>
<br>
<div>[Hidden FlexGrid here]</div>
<div id="hiddenGrid" style="display:none;"></div>
JavaScript
var grid;
var hidden;
// generate some random data
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
data = [];
for (var i = 0; i < 100; i++) {
data.push({
exportRow: ((i % 5 == 0) ? true : false),
country: countries[i % countries.length],
downloads: Math.round(Math.random() * 20000),
sales: Math.random() * 10000,
expenses: Math.random() * 5000
});
}
// create grid and bind data
grid = new wijmo.grid.FlexGrid('#theGrid');
grid.autoSizeMode = "Cells";
grid.itemsSource = data;
function exportToPDF() {
wijmo.grid.pdf.FlexGridPdfConverter.export(grid, 'FlexGrid.pdf', {
scaleMode: wijmo.grid.pdf.ScaleMode.PageWidth,
exportMode: wijmo.grid.pdf.ExportMode.All,
maxPages: 10,
styles: {
cellStyle: {
backgroundColor: '#ffffff',
borderColor: '#c6c6c6'
},
headerCellStyle: {
backgroundColor: '#eaeaea'
}
},
documentOptions: {
info: {
title: 'Sample'
}
}
});
}
function exportSelectedRowsToPDF() {
// copy selected rows of #theGrid to #hiddenGrid
if (hidden == null) {
hidden = new wijmo.grid.FlexGrid('#hiddenGrid');
}
var grid_cv = grid.itemsSource;
var new_cv = new wijmo.collections.CollectionView(grid_cv);
for (var i = 0; i < new_cv.items.length; i++) {
if (!new_cv.items[i].exportRow) {
new_cv.removeAt(i);
i--;
}
}
hidden.itemsSource = new_cv;
//export
wijmo.grid.pdf.FlexGridPdfConverter.export(hidden, 'FlexGrid.pdf', {
scaleMode: wijmo.grid.pdf.ScaleMode.PageWidth,
exportMode: wijmo.grid.pdf.ExportMode.All,
maxPages: 10,
styles: {
cellStyle: {
backgroundColor: '#ffffff',
borderColor: '#c6c6c6'
},
headerCellStyle: {
backgroundColor: '#eaeaea'
}
},
documentOptions: {
info: {
title: 'Sample'
}
}
});
}