0

I have configured the CSV button to work correctly. Now, my client would like a second CSV button to be added to the bottom of the table, as well, so that if someone scrolls to the bottom they don't have to go to the top of table to export.

opentable = $("#open").dataTable( {
    dom: "Bfrtip",
    "data": openData,
    "columns": [{
        data: "severity", render: function (data, type, row) {
            if (type === 'export') {                            
                return data;                        
            } else {                            
                return '';                         
        }          
    }],         
    "paging": true,         
    "searching": true,         
    buttons : [{             
        extend: 'csv',             
        exportOptions: {                 
            columns: [0,1,2,3,4,5,6,7,8,9,10], orthogonal: 'export'             
        }          
    }]        
});

If that's unclear, I'd like to go from the first picture to the second:

Before After

2 Answers 2

1

I played with datatables for hours until I happened upon the dom page and realized that I could add a second B.

My dom is now BfrtBip and this adds a second button before the information (under the table). You can add a second (third, fourth etc...) of anything using this method.

Sign up to request clarification or add additional context in comments.

Comments

0

Perhaps you could clone the class the contains the buttons then prepend it somewhere near the bottom

$(".dt-buttons").clone(true).prependTo(".dataTables_info");

Here is a live example: http://live.datatables.net/tehopova/1/edit

5 Comments

I am following your code exactly, but nothing happens. I tried changing the class selector to other values and still could not achieve any cloning.
In the browser console, are you able to find elements when you do something like $(".dt-buttons") ... (or whatever class surrounds the buttons)? Test if you can manipulate the element by doing something like $(".dt-buttons").hide(); If nothing happens inspect the element carefully to see which selector is correct
The document cannot find the button using the classes. In the $(document).ready(function() {...}) I checked for existence of the button (using .length) and it could not find it. Then, I tried putting the clone in $(window).load(function() {...}) and it only sometimes would find the button and add it the bottom correctly. Other times, it would not find it at all.
You code to clone the buttons should be immediately after the table is created because that is when the classes exist.
I tried this but it still wasn't working. When switching prependTo(...) to insertBefore(...) it worked more consistently. Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.