<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div>
<h2>How to export collapsed data on the grid</h2>
<p>
To include all data in the export, we suggest using the following approach:
</p>
<ol class="styledList">
<li>Copy the current report configuration (line 37 in the JavaScript box). We are going to restore it later.</li>
<li>Subscribe to the <a href="https://www.flexmonster.com/api/aftergriddraw/" target="_blank">aftergriddraw</a> event (lines 40-47).</li>
<li>Expand all data on the grid (line 49). It is needed to temporarily display all collapsed data.</li>
<li>Once we expand the data on the grid, the <code>aftergriddraw</code> event is triggered. In its handler, we export the report and restore the previously saved report configuration (lines 42-46).</li>
</ol>
<p>
<a href="https://www.flexmonster.com/doc/export-and-print/" target="_blank">Visit our documentation to learn more about export in Flexmonster</a>.
</p>
</div>
<button onclick="exportFullGrid()">Export Entire Grid</button>
<div id="pivot-container"></div>
let pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
filename: "data/data.csv"
},
slice: {
rows: [{
uniqueName: "Category",
filter: {
members: [
"category.[accessories]"
]
}
},
{
uniqueName: "Color"
}
],
columns: [{
uniqueName: "[Measures]"
}],
measures: [{
uniqueName: "Price",
aggregation: "sum"
}],
expands: {
rows: [{
tuple: [
"category.[cars]"
]
}]
}
}
}
});
function exportFullGrid() {
// Before the export starts, save the report settings:
const reportCopy = pivot.getReport();
// Remove all filters for the export:
removeAllFilters();
pivot.on("aftergriddraw", () => {
pivot.off("aftergriddraw");
pivot.exportTo('excel', null, () => {
// Export is complete
// Now we can restore the previous report settings (with the filters):
pivot.setReport(reportCopy);
});
});
// Expand the data to include all data in the export:
pivot.expandAllData();
}
function removeAllFilters() {
// Get all selected fields:
let selectedRows = pivot.getRows();
let selectedColumns = pivot.getColumns();
let selectedMeasures = pivot.getMeasures();
let selectedReportFilters = pivot.getReportFilters();
let allSelectedFields = [...selectedReportFilters, ...selectedMeasures, ...selectedColumns, ...selectedRows];
// Remove all filters for the export:
for (let i = 0; i < allSelectedFields.length; i++) {
flexmonster.clearFilter(allSelectedFields[i].uniqueName);
}
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.