There is no built-in feature in DataGrid2 to copy selected rows (with headers) directly to the clipboard in Excel format.
DataGrid2 supports selection, sorting, filtering, etc., but clipboard export is not supported out-of-the-box (as per Mendix Data Widgets documentation).
Add a button:
“Copy to Clipboard”
Pass:
In the microflow:
$result = 'Column1\tColumn2\tColumn3\n'
$result = $result +
$currentObject/Attr1 + '\t' +
$currentObject/Attr2 + '\t' +
formatDateTime($currentObject/DateAttr,'yyyy-MM-dd') + '\n'
Use:
\t → Tab separator (Excel splits columns)\n → New line (Excel splits rows)Create JS Action:
export async function CopyToClipboard(text) {
await navigator.clipboard.writeText(text);
return true;
}
Call it from the microflow with $result.
Yes, there are some workaround solutions to copy DataGrid2 rows to the clipboard, but they are usually short-term fixes and may not be stable or reliable in the long run.
I recommend using Mendix’s export to excel using Excel Exporter module instead. You can add a selection column to your DataGrid2 and export only the selected rows to Excel. This approach ensures that each column is placed in a separate cell and includes the column captions, while also being a more robust and maintainable long-term solution.
Hi Greg,
We have a similar requirement for one of our application.
1. We implemented a simple Java script action to copy the target class of the column.
Drawbacks ; you can always copy one single value and for your columns you need to apply dynamic classes.
2. As mentioned by Ahmet above we used Export to Excel nanoflow called from our DataGrid2 (this is available in DataWidgets module I believe) so that the data is exported as excel or CSV along with all the labels.