Export not working on rows

Export not working on rows

mcsmithemcsmithe Posts: 4Questions: 2Answers: 1

Hi everyone.

I am trying to export my data from the table body, but I get the error Uncaught TypeError: data.replace is not a function. I have the main data that's being drawn by the table as what I want to export. I have those under the class detail-row. I made child rows under the class group that are headers with subtotals that are hidden unless you click the detail-row. This works as expected. I saw the options on what you can choose to include and exclude for imports when you go to the export options, so I wanted to only include the detail-row and thought I had what's required. My code for those is the following:

// Hiding certain details for brevity
drawCallback: function (settings) {
                var api = this.api();
                var rows = api.rows({
                    page: 'current'
                }).nodes();
                var last = null;
                
                // //WORKING SUMMARY HEADER
                api.column(groupColumn, {
                    page: 'current'
                }).data().each(function (affId_offId, i) {
                    if (last !== affId_offId) {
                        $(rows).eq(i).before(
                            '<tr class="group">All the header are in here</td></tr>'
                        );
                        last = affId_offId;
                    }
                });
createdRow: function (row, data, dataIndex) {
                $(row).addClass('detail-row');
            },
buttons: [{
                extend: 'csvHtml5',
                text: '<i class="fi-save"></i> Save to CSV',
                className: 'exportCsvButton',
                filename: 'Multi-Api Report',
                exportOptions: {
                    rows: '.detail-row',
                    // columns: ':not(:eq(2)):not(:eq(2))',
                    format: {
                        body: function (data, row, column, node) {
                            // data = data.replace(/[$]/g, '');
                            // data = data.replace(/[%]/g, '');
                            data = data.replace(/<(?:.|\n)*?>/gm, '');
                            return data;
                        }
                    },
                    modifier: {
                        "search": 'none'
                    }
                }
            }]

Any idea what I am doing wrong? This method has worked before, but now it is not now that I have my toggling headers. Thank you.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @mcsmithe ,

    Yep, that looks like it should work - the data.replace() is used in this example here which is functioning as expected.

    We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.