Regardless of the data content on the grid, I would like to export to excel file with specific field. Please guide me if there is a way.
Hello,
Thank you for reaching out to us.
We recommend using one of the following approaches for exporting Flexmonster to Excel with the additional field:
reportcomplete
and exportcomplete
events. The idea is to add the necessary column to the slice object and set a new slice via runQuery
API call before export. After the export is completed, you can remove the added column from the slice. Please check the following example for reference: https://jsfiddle.net/flexmonster/btjhyn08/.Please let us know if it works for you. Looking forward to hearing from you.
Kind regards,
Nadia
In method 1, Is it possible to make two export buttons, one to export what is seen inside the grid, and the other to export a specific field (which may or may not be on the grid in some cases)?
Hello,
Thank you for the response.
It is possible to create two separate functions:
1) To export what is seen inside the grid, you can use the exportTo("excel")
API call without additional logic:
function excelCurrentGrid() {
pivot.exportTo("excel");
}
2) To export a specific field:
function excelOneField() {
let oldSlice = pivot.getReport().slice
// slice with only a specific field
let newSlice = {
columns: [{ uniqueName: "Country" }],
}
// return a previous grid state
pivot.on("reportcomplete", function () {
pivot.off("reportcomplete")
pivot.exportTo("excel")
pivot.on("exportcomplete", function () {
pivot.off("exportcomplete")
pivot.runQuery(oldSlice)
})
})
pivot.runQuery(newSlice)
}
Please let us know if it works for you. Looking forward to hearing your feedback.
Kind regards,
Nadia