Export to Excel -- way to use different TH value in export.

Export to Excel -- way to use different TH value in export.

lisarushlisarush Posts: 102Questions: 17Answers: 0

Is there a way to use different table header text in the exported version, vs. the screen version.
It would be nice to be able to do something like this, so that the screen could show a time duration in human-readable format but the Excel export just have the total # of minutes -- and the spreadsheet header reflect the Units:

<table>
   <thead>
        <tr>
            <th data-sort="Duration (minutes)">  Duration (HH:mm)  </th>
        </tr>
    </thead>
    <tbody>
        <tr>
           <td data-sort="150">  2:30  </td>
        </tr>
     </tbody>
 </table>

specifying exportOptions.orthogonal = 'sort'

Is there a way to do this?

Answers

  • kthorngrenkthorngren Posts: 21,315Questions: 26Answers: 4,948

    See if this thread helps to customize the header export.

    Kevin

  • allanallan Posts: 63,482Questions: 1Answers: 10,467 Site admin

    Yes, a custom formatting function for the header is probably the best way to do it.

    However, if you need to based a calculation from the other rows in the table (your question makes it sound like you might was to sum the values?) then use customizeData from buttons.exportData() which lets you overwrite the values that have been read in.

    I can put an example of that together for you if you like. I'm just not clear on if you are doing a sum or not.

    Allan

  • lisarushlisarush Posts: 102Questions: 17Answers: 0

    It looks like the example from the thread Kevin linked should help me. (I do not need to do a sum.)

    I essentially just want the Screen vs Export column to be formatted differently: in a nice human-readable form for the screen -- vs. a straight number for the export. This is easy to do for the column <td> value itself, via the orthogonal option and using, for example, data-sort on the <td> cell.

    Would it be possible to request that the orthogonal option also support using, for example, data-sort for the <th> cells, as well? That would be an easy and consistent way to do it...?

  • allanallan Posts: 63,482Questions: 1Answers: 10,467 Site admin

    The orthogonal concept doesn't extend beyond the data in the table body at the moment. I'd need to have a think about how to introduce it beyond that, but you are right it might be sensible to do so. I need to have a think about what other areas it might be useful. It it is only export, then improving the formatting functions or perhaps introducing an orthogonal approach only there might be the way to do it.

    Let me know how you get on with!

    Allan

  • lisarushlisarush Posts: 102Questions: 17Answers: 0

    I was able to implement this in a generic way for us. (We have an extension to dataTables, so that we can set & provide features, etc. in common across all tables.)

               exportOptions.format = {
                   header: function( html, colIdx, node ) {
                      if ( html &&  // found html text (will be empty if column header spans cols, so skip those)
                           node &&  // found element
                           node.dataset[exportOptions.exportDataType] ) {  // has 'data-' value set
                         return node.dataset[exportOptions.exportDataType];
                      } else {
                         return html;
                      }
                   }
                };
    

    Thanks for the starting help.

  • allanallan Posts: 63,482Questions: 1Answers: 10,467 Site admin

    Very nice! Thanks for letting us know you've got it working as you need.

    Allan

Sign In or Register to comment.