DataGrid2 Copy/Paste

0
Hi Mendix Community, I am looking for a solution to copy the selected rows of a DataGrid2 to the clipboard.  And when pasted into Excel, each column is in a separate cell and the column captions are included. Is anyone aware of a solution like this? Thanks in advance.
asked
3 answers
0

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).

Recommended Working Solution (Production-Ready)

Approach: Use a Microflow + JavaScript Action

Step 1 – Enable Selection in DataGrid2

  • Set Selection mode = Multi
  • Use an On selection change action
  • Store selected objects in a page variable (List)

Step 2 – Create Microflow Button

Add a button:

“Copy to Clipboard”

Pass:

  • Selected object list
  • Optional: Entity metadata (column names)

Step 3 – Build Tab-Separated String (Excel Compatible)

In the microflow:

  1. Create a String variable:

$result = 'Column1\tColumn2\tColumn3\n'
  1. Loop through selected objects
  2. Append per row:

$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)

Step 4 – JavaScript Action (Clipboard API)

Create JS Action:


export async function CopyToClipboard(text) {
    await navigator.clipboard.writeText(text);
    return true;
}

Call it from the microflow with $result.

answered
0

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.


answered
0

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.

answered