Search code examples
jqueryhtmldatatables

Remove Custom button from Datatable


enter image description here

How can I remove the Copy, CSV, Excel, PDF and Print button on the top right corner. They are the default feature of datatables I suppose. I am trying to remove them but I did not find nay information on how can I remove or hide them.

Following is the code

oTable = $('#lenderList').dataTable(
        {
            bServerSide: true,
            bProcessing: true,
            searching: true,
            sAjaxSource: "loanAdminAjax?ajax=true&searchCol="+$('#category').val(),
            sServerMethod: 'POST',
            sPaginationType: "full_numbers",
            bPaginate: true,
            bLengthChange: true,
            bFilter: true,
            bSort: true,
            bInfo: true,
            bAutoWidth: true,

            aoColumns: [
                {
                    "sName": "loanApplicationNumber",
                    mData: "loanApplicationNumber"
                },
                {
                    "sName": "name",
                    mData: "name"
                },
                {
                    "sName": "submissionDate",
                    mData: "submissionDate"
                },
                {
                    "sName": "kycEmailId",
                    mData: "kycEmailId"
                },
                {
                    "sName": "appVersion",
                    mData: "appVersion"
                },
                {
                    "sName": "documentStatus",
                    mData: "documentStatus"
                },
                {
                    "sName": "latestRemark",
                    mData: "latestRemark"
                },
                {
                    "sName": "appName",
                    mData: "appName"
                }


            ],
            "dom": 'T<"clear"><"button">lfrtip'



        }
    );

Solution

  • This is the default datatable:

    <html>
        <head>
            <link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css" />
            
            <script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
            <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
            
            <script type="text/javascript" language="javascript" class="init">
            $(document).ready(function() {
                var data = [];
                data.push(
                    [1,"Sasha","Brenna","0800 1111"],
                    [2,"Sage","Mia","(01012) 405872"],
                    [3,"Chelsea","Allistair","076 0578 0265"],
                    [4,"Uta","Savannah","070 1247 5884"],
                    [5,"Remedios","Berk","0995 181 0007"],
                    [6,"Ruby","Wayne","0800 1111"],
                    [7,"Faith","Fredericka","(01709) 099879"],
                    [8,"Myra","Harrison","070 4241 9576"],
                    [9,"Drake","Miriam","0800 733635"],
                    [10,"Reed","Shannon","076 8597 5067"]
                );
                 
                $('#data_table').DataTable( {
                    data: data
                });
            });
            </script>
            
            <style>
            .odd{
                background-color: #FFF8FB !important;
            }
            .even{
                background-color: #DDEBF8 !important;
            }
            </style>
        </head>
        <body>
        <div>
    
        <table id="data_table">
            <thead>
                <tr>
                    <th>Emp Code</th>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Mobile</th>
                </tr>
            </thead>
    
            <tbody>
            <!-- Dynamic Body -->
            </tbody>
        </table>
    
        </body>
        </div>
    </html>

    In the above example, their are no such buttons. To show the specified buttons you have to include:

    dom: 'Bfrtip',
            buttons: [
                'copy', 'csv', 'excel', 'pdf', 'print'
            ]
    

    and their corresponding js files. To remove these buttons, just remove the above code from your datatable initialization code.