Export options - Modifier - Do not export table head

Export options - Modifier - Do not export table head

jollywoodjollywood Posts: 8Questions: 3Answers: 0
edited October 2015 in Free community support

Hi,

two short questions. I've a button like this:

  extend: 'copy',
  text: 'Copy selected rows to clipboard',
  exportOptions: {
         modifier: {
               selected: true
          }
   }

1) I don't want it to copy the first column. How can I archive this?

2) I dont' want it to copy the table head. Just the plain data. Is there an option for that?

Thank you so much for your help.

Edit: There was an easy setting in the previous version of Datatables: http://legacy.datatables.net/extras/tabletools/button_options (bHeader and mColumns), but I can't find any information how to use them in 1.10+. Also, how I can use mColumns to deselect the first column instead of listing every enabled column. Any help would be appreciated.

Edit2: I'm using the nightly, that's why I'm not affected by the 'export selected rows' bug.

This question has accepted answers - jump to:

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited October 2015 Answer ✓

    copy Look at the available options

    header boolean true
    Indicate if the table header should be included in the exported data or not.

  • jollywoodjollywood Posts: 8Questions: 3Answers: 0
    edited October 2015

    Alright, thanks. So there's just one question left: How can I exclude a specific column from copy?

    Edit: changed row to column

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    In the same copy page, look at the exportOptions options, it buttons.exportData(), the very first one listed on there is rows, which takes any type of row-selector, so you can pass it an anonymous function that will select whatever rows you want.

    As an example, heres the value of my exportOptions for my button, if any rows are selected, then it will only export those selected rows, if no rows are selected, then it will export all rows..

    new $.fn.dataTable.Buttons( $dt, {
        buttons: [
            {
                text: 'Copy',
                extend: 'copy',
                exportOptions: {
                    rows: function ( idx, data, node ) {
                        // If rows are selected, export those, if not, export all
                        if($dt.rows( { selected: true } ).any())
                            return $.inArray(parseInt(data.asset_id), $dt.rows( { selected: true } )) !== -1;
    
                        return true;
                    }
                }
            }
        ]
    } );
    
  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited October 2015

    Heres an example I created, it uses print instead of copy, but for some reason, the copy didnt work in there, might have something to do with it being inside a jsbin instance.. but the exportOptions logic is the same

    That also strips off the header of the table

  • jollywoodjollywood Posts: 8Questions: 3Answers: 0

    Oh, my bad. I meant 'how to exclude specific columns from copying'. I'm so sorry. Thank you for your help anyway, even though it's not the solution I'm looking for.

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    Answer ✓

    Well in that case, theres also a columns option which takes a column-selector, just like the rows

This discussion has been closed.