Can I Add a Button to Export a Repeated Section to Excel?


Badge +7

I have a repeating section that is basically an itemized invoice. The customer would like to export the itemized list to Excel (or csv), by clicking a button on the form. Is there a way to do this?


4 replies

Userlevel 5
Badge +14

I played with something similar some time ago. but it was bit more complex then just to export repeating section (but repeating was important part of what need to be exported)

first I evaluated DataTables (https://datatables.net/ ). they seemed very promising at first sight, but I haven't managed to get it working together with nintex at that time.

Does anyone have experience with integrating the DataTables JavaScript library with Nintex Forms on-prem? 

ended up creating custom page with list view webpart and with client side rending I redesigned page layout from the scratch to look like table I needed to export.

then I used a javascript triggered by button that converted HTML table to csv.

see one of possible approaches Export Table Data to CSV using Javascript · GitHub  

I had to approach it that way since I haven't had available enterprise features.

I believe with enterprise features (DocGen, excel services...) it might be much easier.

Badge +7

I'm very excited to say I've figured this out. Unfortunately this is a draft. I call it that because the part that is currently exporting to excel is table2excel which is not meant for production as it is only reliable in Chrome, and sometime FireFox. None-the-less this works, and in a way that will easily segway to a better export solution. You should be able to replace table2excel with another method to export, but this will give you an idea of how to make it happen.

1. We mapped out how Nintex renders repeating sections. However, this proved unnecessary, because all we needed was to use the "data-controlname" attribute of each field to collect data.(i.e. data-controlname="field1")

2. We then used a little javascript, html, and css to build the HTML table and hide it on the page. The HTML goes in a label on the actual form where you want the Export button to render. The CSS goes in the custom CSS in form settings, and the JS can go in the custom JS in settings, however we put this in an external file and included it in the JS includes section of the advanced section in form settings. 

/*****HTML*********************************/

<table id="tableID">
<th>Item Number</th>
<th>Part Number</th>
<th>Description</th>
<th>Qty</th>
<th>Unit Cost</th>
<th>Total Cost</th>
</table>

<button id="btnexport">Export</button>

/*****CSS*********************************/

#tableID{display:none;}

/*****JAVASCRIPT*********************************/

// Get a handle to the table
var printTable = ("#tableID");

// Get arrays of all data points
var unitCosts = $("div[data-controlname='txt-unitCost']");
var itemTotals = $("div[data-controlname='cal-itemTotal']");
var quantities = $("div[data-controlname='txt-qty']");
var itemNums = $("div[data-controlname='calc-itemNum']");
var partNums = $("div[data-controlname='txt-partNum']");
var descriptions = $("div[data-controlname='txt-description']");

var itemCount = itemNums.length;

// build the table by 
for(var itemIndex = 0; itemIndex < itemCount; itemIndex++) {
var strRow = "<tr><td>" + $(itemNums[itemIndex]).text() + "</td>"
+ "<td>" + $(partNums[itemIndex]).text() + "</td>"
+ "<td>" + $(descriptions[itemIndex]).text() + "</td>"
+ "<td>" + $(quantities[itemIndex]).text() + "</td>"
+ "<td>" + $(unitCosts[itemIndex]).text() + "</td>"
+ "<td>" + $(itemTotals[itemIndex]).text() + "</td>";

$(printTable).append(strRow);
}

3. Then we applied table2excel the JS was included in the same file mentioned above.

FINAL RENDER:

 

Badge +1

Dear Josh Henderson,

I am working on the same requirement in nintex like you, can you please share with me the complete script when click on "Export Details" button.

Regards,

Badge +7

Very cool. I've also dabbled getting data from a repeating section into excel a different way...

https://community.nintex.com/community/dev-talk/blog/2018/10/10/repeating-section-extract-and-split-to-excel

This though, dumps all of the lists items repeating sections into excel.

T.

Reply