How to get the list of objects from datagrid2 client-side ( after filters and sorting of the user)

0
Hello everyone,  I have a datagrid2 where the user can filter by text, sort, ... After he has done his actions, he clicks on a nanoflow  button. I want this NF to retrieve the same list in the datagrid2 client-side. For now, I get the String version of it with the following Javascript action: /** * @param {string} datagridName * @returns {Promise.<string>} */ export async function JS_GetWithString(datagridName) { // BEGIN USER CODE if (!datagridName) { throw new Error("Datagrid name is required."); } return new Promise((resolve, reject) => { const stream = window[window.DATAGRID_DATA_EXPORT][datagridName].create(); let dataList = []; const streamOptions = { limit: 1000 }; // You can adjust the chunk size if needed stream.process((msg) => { if (!msg) { return; } switch (msg.type) { case "data": // Filter out the last column from each row const filteredData = msg.payload.map(row => row.slice(0, -1)); dataList = dataList.concat(filteredData); break; case "end": const jsonString = JSON.stringify(dataList); resolve(jsonString); break; case "aborted": reject(new Error("Data export aborted.")); break; default: break; } }, streamOptions); stream.start(); }); // END USER CODE }   Can you help me to make this list returns a list of objects instead of a string please? Thank you so much. NB: I tried many times but I couldn't make it work when the return is * @returns {Promise.<MxObject[]>}
asked
1 answers
0

You have defined you javascript to return a string:

* @returns {Promise.<string>}

You did this in the javascript-ui in Studio by setting the return type:

image.png

You first have to change the return type to List of 'yourobject'

image.png

Then regenerate your javascript by restarting you app.

Then modify your javascript, where you can remove the Stringify commands and just keep the objectlist, which you can now return directly.

 

answered