Copy extension to copy on a particular column using name
Copy extension to copy on a particular column using name
I have a dynamically generated table on the server with varying column numbers and names. I want to provide user an option to copy a particular column by name (which is always present). Somehow it is not working. It comes back with 0 records exported.
I have posted an example at http://live.datatables.net/rumewuko/1/edit
The relevant javascript portion is below. I am suspecting that my columns syntax is not write but can't say for sure?
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
{ extend: 'copy', className: 'btn btn-primary' },
{ extend: 'csv', className: 'btn btn-primary' },
{ extend: 'excel', className: 'btn btn-primary' },
{
extend: 'copy',
text: 'Copy Office',
className: 'btn btn-primary',
header: false,
exportOptions: {
columns: ['Office:name']
}
}
]
} );
} );
</script>
Also is it possible to add some space between the buttons? Even though I have overwritten the style it seems to carry the default style and does not leave any space between buttons.
Answers
Seems like you will need to use a function for the column selector. This works:
Here is your example updated:
http://live.datatables.net/miworana/1/edit
Found some ideas here for button spacing:
http://stackoverflow.com/questions/27689927/how-to-give-spacing-between-buttons-using-bootstrap
Added one of the options to the above.
Kevin
The problem with the defined code is that there is no column with the name
Office
. The name is not the same as the title, instead the name is given bycolumns.name
which is not defined in the example, thus there is no name for any of the columns.Allan
Thanks kthorngren
However your copy office example is not working. It is copying the entire table to the clipboard. The expected result is that only Office column would be copied.
Allan The table columns are dynamic. I don't know and can't hardcorde which columns would be presented. I need a way to show the "Copy Office" button if a column with Office button shows up on the output.
You should be able to use
:contains("...")
as a jQuery selector to select a column. That works withcolumn()
, but doesn't appear to work with the export options for some reason: http://live.datatables.net/rumewuko/3/edit .I fully expected that to work. I'll take a look into why it isn't.
Allan
Actually no - that works perfectly. I was clicking the Copy button rather than Copy Office. Doh. Too much time debugging, not enough time looking .
Allan