Hi,
I want to use Flexmonster's Export To CSV api without binding data to Pivot Control.Is it possible to use this api from other page just for exporting content to CSV.My page contains list of all reports, on clicking it, it should export content to CSV. Can I use Flexmonster.JS for this?
Hello, Om,
Thank you for your interest in Flexmonster Pivot!
Export To CSV feature is applicable only to the content currently displayed on the grid. However, you can create Flexmonster instance without using a browser by means of PhantomJS. Please have a look at the following tutorial: How to export on the server without using a browser.
Let me know if you have any other questions.
Regards,
Tanya
Thank you Tanya for the quick reply. But I have to use Flexmonster's ExportAPI feature Without showing Pivot Grid.
In order to achieve this I believe, I need to bind data first to the PivotContainer and then use ExportAPI. Is this possible to achieve this by keeping PivotContainer Grid(div) hidden.
Hi Tanya,
Here I am providing more details.
I added one button in HTML and Export functionality on click event and kept div of Pivot Container hidden.
Please find below HTML and Javascript code for the same.
It's working but columns are not appearing in exported CSV file. How to make these columns visible in CSV file.Additionally I attached CSV file
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div id="pivot-container" style="display: none;"></div>
<button onclick="ExportCSV()">Export CSV</button>
JS
var pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 430,
toolbar: true,
report: {
dataSource: {
filename: "data/sales.csv",
},
slice: {
rows: [{
uniqueName: "Month"
}, {
uniqueName: "[Measures]"
}],
columns: [{
uniqueName: "Category",
levelName: "Product Name",
filter: {
members: [
"category.[condiments].[bbq sauce]",
"category.[breakfast cereals].[corn flakes]",
"category.[confectionery]",
"category.[bakery].[chocolate biscuits]",
"category.[fruit preserves].[apple jam]",
"category.[bakery].[apple cake]",
"category.[soups].[tomato soup]"
]
}
}],
measures: [{
"uniqueName": "Revenue",
"aggregation": "sum",
"format": "2sfou03a"
}]
},
conditions: [{
formula: "#value < 2500",
measure: "Revenue",
format: {
backgroundColor: "#df3800",
color: "#FFFFFF"
},
isTotal: false
},
{
formula: "#value > 20000",
measure: "Revenue",
format: {
backgroundColor: "#00A45A",
color: "#FFFFFF"
},
isTotal: false
}],
formats: [{
name: "2sfou03a",
thousandsSeparator: ",",
decimalSeparator: ".",
decimalPlaces: 2,
currencySymbol: "$",
currencySymbolAlign: "left",
nullValue: "",
textAlign: "right",
isPercent: false
}]
}
});
ExportCSV = function()
{
pivot.exportTo('csv');
}
Hello, Om,
Thank you for your quick reply and specifying additional details.
For your scenario, the best option is to use PhantomJS. PhantomJS is a headless web browser scriptable with JavaScript. This means it allows using Flexmonster’s ExportAPI feature without showing Pivot Grid. With the help of the simple script, you can load an HTML page with Flexmonster instance, and export its content as CSV. Please note, that Pivot Grid is not visible in this case.
Here is PhantomJS homepage: http://phantomjs.org/. Also, the link to a sample GitHub project with such export might be useful as well: https://github.com/flexmonster/pivot-phantomjs.
Please let me know whether you have managed to configure everything successfully.
Regards,
Tanya