Can a column be defined to render different for view vs Printing?

Can a column be defined to render different for view vs Printing?

desperadodesperado Posts: 159Questions: 33Answers: 4
edited March 2018 in Free community support

I have been reading about the columns.render option but I can't figure out from what I am reading if I can have different rendering for options like Print, PDF, Excel vs the displayed data on the table.

I see options for sort and display but not for export or print. Since Print, PDF, Excel are built in I was hoping that I can render differently for them.

For example I am using ellipsis.js to render a long title.
It displays the text truncated but I would like the excel export to contain the full text. For this field I would probably like shortened text for print but perhaps not. Ideally if I can control print, excel, pdf, copy differently that would be great.

I tried searching the forums for this topic but failed to find. Sorry if I missed obvious posts. I did try to research this as much as possible first.

Another example I have is a column I am have which lets a user take action based on buttons in the column. I have a column called "assigned to" which displays who a project is assigned to. When I render this I want to add a button for "assign to me". At first I did this by just returning HTML and adding some javascript to render these buttons and that is working but the text "assign to me" is included in the print options which I don't want. So I plan on writing my own render to add this button. But I want that renderer to NOT included the button when printing or exporting.

I hope this all makes sense. Thanks to anyone that can point me in the right direction of an example which does what I am trying to do or to some more documentation that might explain how it's done.

I can post example if needed but I think the case is simple enough. Let me know :smile:

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi desperado,

    Take a look at this example - this has different rendering formats for CSV and XLS exports. You can easily add another for print/pdf/etc.

    Hope that helps,

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 21,141Questions: 26Answers: 4,918
    Answer ✓

    This example explains how to use columns.render to render data for exporting:
    https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html

    Kevin

  • desperadodesperado Posts: 159Questions: 33Answers: 4
    edited March 2018

    Wow that was fast! Thanks for making first experience with the community such a good on! I will try these and return to mark answered if I get them working. I believe I will!

  • desperadodesperado Posts: 159Questions: 33Answers: 4

    Sweet, got it working. Thanks so much guys! The key was adding the orthogonal export option to the buttons. Namely
    exportOptions: { orthogonal: "excel" }
    exportOptions: { orthogonal: "copy" }
    exportOptions: { orthogonal: "print" }
    exportOptions: { orthogonal: "pdf" }
    so type is set to excel, copy, print and pdf .

    Now I can show log text for excel and copy but not for print and pdf. Love it!

This discussion has been closed.