How do you delete the print button?

How do you delete the print button?

JoeJoeJoeJoeJoeJoe Posts: 50Questions: 13Answers: 1

I cannot for the life of me figure out how to remove the "print" button from my table. Any ideas? Thanks

This question has an accepted answers - jump to answer

Answers

  • glimpsed_chaosglimpsed_chaos Posts: 138Questions: 29Answers: 4

    Remove it from the buttons. You may have other buttons...

    $(document).ready(function() {
        $('#example').DataTable( {
            dom: 'Bfrtip',
            buttons: [
                'print'
            ]
        } );
    } );
    
  • JoeJoeJoeJoeJoeJoe Posts: 50Questions: 13Answers: 1

    Thanks for the answer, however I have tried that before and again now, and it's not working. Could there be another function that cancels this one out?

            $(function LogTable() {
    
                //var sCsrfToken = $("input[name='__RequestVerificationToken']").val();
                //if (typeof sCsrfToken !== "string") {
                //    sCsrfToken = "";
                //}
    
    
                $.ajax({
                    url: "Home/GetTaskLog",
                    type: 'post',
                    processData: 'false',      
                    contentType: "application/json; charset=utf-8",
                    dataType: 'json',
                    success: function (data) {
                        xyz(data)
                    }
                });
            });
    
    
            function xyz(data) {
                $('#WTM_LOG').dataTable({
                    dom: 'Brtp',
                 buttons: [
                     'print'],
    
                    'order': [[0, 'desc']],
                    "pageLength": 20,
                    "data": JSON.parse(data),
                    "columns": [
                        {
                            "data": "TaskName",
                            "visible": false
                        },
                        {
                            "data": "StartDate",
                            "render": function (data, type, row) {
                                var dateSplit = data.split("");
                                return type === "display" || type === "filter" ?
                                    dateSplit[8] + dateSplit[9] + '/' + dateSplit[5] + dateSplit[6] + '/' + dateSplit[0] + dateSplit[1] + dateSplit[2] + dateSplit[3] + " " + dateSplit[11] + dateSplit[12] + ":" + dateSplit[14] + dateSplit[15] + ":" + dateSplit[17] + dateSplit[18] :
                                    data;
                            },
                        },
                        {
                            "data": "EndDate",
                            "render": function (data, type, row) {
                                var dateSplit = data.split("");
                                return type === "display" || type === "filter" ?
                                    dateSplit[8] + dateSplit[9] + '/' + dateSplit[5] + dateSplit[6] + '/' + dateSplit[0] + dateSplit[1] + dateSplit[2] + dateSplit[3] + " " + dateSplit[11] + dateSplit[12] + ":" + dateSplit[14] + dateSplit[15] + ":" + dateSplit[17] + dateSplit[18] :
                                    data;
                            },
                        },
                        {
                            "data": "ErrorCount",
                            "render": function (data, type, row) {
                                return (data == 0)
                                    ? data = ''
                                    : data = '<i class="fas fa-exclamation-triangle" style="color:red"></i>'
                            },
                        },
                        {
                            "data": "EventCount",
                            "render": function (data, type, row) {
                                return (data == 1)
                                    ? data = '<i id="warning" class="fas fa-list" style="color:blue"></i>'
                                    : data = ''
                            },
                        }
                    ]
    
                });
    
                //error: function (a, b, c) {
                //    var i = 1;
                //}
    
    
    
                var table = $('#WTM_LOG').DataTable();
    
                //table.column('0:visible').order('desc').draw();
    
                $('#from').datepicker({
                    dateFormat: "dd-mm-yy",
                    maxDate: "0",
                    changeMonth: true,
                    changeYear: true,
                    onClose: function (selectedDate) {
                        table.draw();
                    }
                });
    
                $('#to').datepicker({
                    dateFormat: "dd-mm-yy",
                    maxDate: "0",
                    changeMonth: true,
                    changeYear: true,
                    onClose: function (selectedDate2) {
                        table.draw();
                    }
                });
    
                $('.switch').on('click', function () {
    
                    //search function
                    $('#WTM_LOG').DataTable().search('warning').draw();
    
                })
    
            }
    
  • kthorngrenkthorngren Posts: 21,242Questions: 26Answers: 4,929
    edited November 2018

    This will definitely display the print button:

         buttons: [
             'print'],
    

    Do you have other buttons you want to display?

    If so then place them in the buttons.

    If you don't want any buttons displayed then remove the B from dom: 'Brtp', to look like dom: 'rtp',.

    Kevin

  • JoeJoeJoeJoeJoeJoe Posts: 50Questions: 13Answers: 1

    Oh, sorry I had completely misunderstood. I thought I was being asked to add that code, not remove it.

    so I have the following code only :

    'dom': 'Brtp',

    I have removed this code from the above:

    buttons: [
    'print'],

    and yet the print button is still showing. The reason I still need the B in 'Brtp', is because I need buttons for pagination (next, previous etc.). The irony is that I can't get the buttons to show up for pagination either, this is what they look like:

    https://imgur.com/a/tH9HJgM

    I have no idea what I'm doing wrong.

  • colincolin Posts: 15,238Questions: 1Answers: 2,599

    Hi @JoeJoeJoe ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 21,242Questions: 26Answers: 4,929
    Answer ✓

    The B dom option is only for the export buttons and does not affect the paging buttons. You can see this in this example with just 'dom': 'rtp',.
    http://live.datatables.net/qihogujo/1/edit

    The paging buttons are showing in your screenshot. The problem is they are links not buttons. That suggests a CSS issue. I would first make sure you have all the correct Datatables JS and CSS files. The easiest way is to use the Download Builder. If this doesn't help then as Colin mentions we will need a link to your page or a test case replicating the issue.

    Kevin

This discussion has been closed.