How can I remove the search bar and footer added by the jQuery DataTables plugin?

前端 未结 19 2604
孤街浪徒
孤街浪徒 2020-12-07 07:45

I am using jQuery DataTables.

I want to remove the search bar and footer (showing how many rows there are visible) that is added to the table by default. I just wan

相关标签:
19条回答
  • 2020-12-07 07:59

    If you are using custom filter, you might want to hide search box but still want to enable the filter function, so bFilter: false is not the way. Use dom: 'lrtp' instead, default is 'lfrtip'. Documentation: https://datatables.net/reference/option/dom

    0 讨论(0)
  • 2020-12-07 07:59

    I think the simplest way is:

    <th data-searchable="false">Column</th>
    

    You can edit only the table you have to modify, without change common CSS or JS.

    0 讨论(0)
  • 2020-12-07 08:00

    As said by @Scott Stafford sDOM is the most apropiated property to show, hide or relocate the elements that compose the DataTables. I think the sDOM is now outdated, with the actual patch this property is now dom.

    This property allows to set some class or id to an element too, so you can stylish easier.

    Check the oficial documentation here: https://datatables.net/reference/option/dom

    This example would show only the table:

    $('#myTable').DataTable({
        "dom": 't'
    });
    
    0 讨论(0)
  • 2020-12-07 08:00
    <script>
    $(document).ready(function() {
        $('#nametable').DataTable({
            "bPaginate": false,
            "bFilter": false,
            "bInfo": false
        });
    });
    </script>
    

    in your datatable constructor

    https://datatables.net/forums/discussion/20006/how-to-remove-cross-icon-in-search-box

    0 讨论(0)
  • 2020-12-07 08:01

    As of DataTables 1.10.5 it is now possible to define initialisation options using HTML5 data-* attributes.

    -dataTables documentation: HTML5 data-* attributes - table options

    So you can specify data-searching="false" data-paging="false" data-info="false" on the table. For example, this table will not allow searching, apply paging, or show the information block:

    <table id="example" class="display" width="100%" data-searching="false" data-paging="false" data-info="false">
        <thead>
            <tr>
                <th>Name</th>
                <th data-orderable="false">Avatar</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Tiger Nixon</td>
                <td><img src="https://www.gravatar.com/avatar/8edcff60cdcca2ad650758fa524d4990?s=64&amp;d=identicon&amp;r=PG" alt="" style="width: 64px; height: 64px; visibility: visible;"></td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>
            <tr>
                <td>Garrett Winters</td>
                <td><img src="https://www.gravatar.com/avatar/98fe9834dcca2ad650758fa524d4990?s=64&amp;d=identicon&amp;r=PG" alt="" style="width: 64px; height: 64px; visibility: visible;"></td>
                <td>2011/07/25</td>
                <td>$170,750</td>
            </tr>
            ...[ETC]...
        </tbody>
    </table>
    

    See a working example at https://jsfiddle.net/jhfrench/17v94f2s/.

    The advantage to this approach is that it allows you to have a standard dataTables call (ie, $('table.apply_dataTables').DataTable()) while being able to configure the dataTables options table-by-table.

    0 讨论(0)
  • 2020-12-07 08:03

    For DataTables >=1.10, use:

    $('table').dataTable({searching: false, paging: false, info: false});
    

    For DataTables <1.10, use:

    $('table').dataTable({bFilter: false, bInfo: false});
    

    or using pure CSS:

    .dataTables_filter, .dataTables_info { display: none; }
    
    0 讨论(0)
提交回复
热议问题