Export CSV - Can't change footer value when value are modify using exportOptions

Export CSV - Can't change footer value when value are modify using exportOptions

pat.thizypat.thizy Posts: 7Questions: 2Answers: 0

With the DataTables.js v3.0.0, when I try to modifiy avec value in the footer, my value in not taken in account. In the CSV file, I always found then value which is in the table and not the returned value
I don't have this problem with the body

I tried with an older version (1.5.1), this problem does not exist

exportOptions: {
//footer : true,
format: {
body: function (data, row, column, node) {
return remove_char_not_numeric(data, node)
},
footer: function (data, row, column, node) {
return remove_char_not_numeric(data, column);
},

Answers

  • kthorngrenkthorngren Posts: 20,420Questions: 26Answers: 4,793

    The issue was posted in this thread. You should find the fix in the datatables and buttons nightly downloads. I think the fixes will find their way into the next releases of datatables and buttons.

    Kevin

  • pat.thizypat.thizy Posts: 7Questions: 2Answers: 0
    edited March 4

    I actually noticed the same problems as those reported in the commits. I applied all these fixes because my library is installed locally (I downloaded the files from the DataTables.net site)

    The problem I see is the following:
    In cell th of my header or footer I have for example the value 1234.
    In export options I return "TEST" + data
    Unfortunately in the CSV I find 1234 and not TEST 1234

    exportOptions: {
        format: {
          body: function (data, row, column, node) {
                return "TEST" + data;
    },
    

    To temporarily fix this problem I modified the header and footer code locally here :
    In datatables.js line 102745

    if (config.footer && data.footer) {
            footer = data.footer.join(separator);
    and comment this
    /*data.footerStructure
                    .map(function (row) {
                        return join(
                            row.map(function (cell) {
                                return cell ? cell.title : '';
                            })
                        );
                    })
                    .join(newLine) + newLine;*/
    

    for my use case it's enough

    Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

  • pat.thizypat.thizy Posts: 7Questions: 2Answers: 0

    Small clarification, if I use version 1.5.1 of datatables I do not notice this problem
    When the same code in exportOptions I see TEST 1234 in the CSV without modifcation in the library

  • kthorngrenkthorngren Posts: 20,420Questions: 26Answers: 4,793

    I built a test case for you using all nightly code:
    https://live.datatables.net/fuyiyaxu/1/edit

    The header nor the footer are modified with the exportOptions format function. @allan will need to take a look.

    Kevin

  • pat.thizypat.thizy Posts: 7Questions: 2Answers: 0

    Your example reflects exactly the problem I see
    Thanks a lot

  • allanallan Posts: 61,950Questions: 1Answers: 10,158 Site admin

    Could you post a link to your page showing the issue so I can trace it through please?

    The version numbers mentioned are a bit mixed up - there is no DataTables 3 for example, and 1.5.1 is ancient (2009), so I'd like to check what it is that you are actually using.

    Many thanks,
    Allan

  • kthorngrenkthorngren Posts: 20,420Questions: 26Answers: 4,793

    You may have missed it but I posted a test case showing the issue.

    Kevin

  • kthorngrenkthorngren Posts: 20,420Questions: 26Answers: 4,793

    Also this thread is reporting the same issue.

    Kevin

  • allanallan Posts: 61,950Questions: 1Answers: 10,158 Site admin

    Yup - bit of post overlap there, sorry about that. Thanks for the test case Kevin - I can indeed see the issue there. Wonder how I've broken it this time... :)

    Will be back shortly once I've fixed it.

    Allan

  • allanallan Posts: 61,950Questions: 1Answers: 10,158 Site admin

    Fixed here and the example with the nightly is now working as expected.

    I wasn't passing the header and footer titles from the new multi-row header and footer functions through the formatters. It happens now though.

    Thanks for the test case Kevin - is makes this so much easier. Thank you!

    Allan

  • chboccachbocca Posts: 86Questions: 13Answers: 1

    But this update is not yet released, correct?

  • allanallan Posts: 61,950Questions: 1Answers: 10,158 Site admin

    That is correct. I've not yet tagged a release version with the fix.

    Allan

  • chboccachbocca Posts: 86Questions: 13Answers: 1

    See latest release is out and this issue seems resolved.

    Thank you!

  • langelange Posts: 9Questions: 3Answers: 0

    It works with me now. Thank you again!

Sign In or Register to comment.