【问题标题】:Datatables no sorting or search on some of my tables数据表没有对我的一些表进行排序或搜索
【发布时间】:2020-10-19 11:32:22
【问题描述】:

在我的一些数据表上没有显示排序和搜索。红框是我想要显示的,但我无法让它们在我的某些桌子上显示你。数据表完全相同,我复制了代码但没有任何改变。所以我问是否有人对我有解决方案?

下面你会看到我的一些 javascript 和 html 代码:

--- javascript ---
$("#dataTablesFull, #dataTablesFull2, #dataTablesFull3, #dataTablesFull4").dataTable( {
                    "pageLength": <?php echo getConfigValue("table_records"); ?>,
                    "dom": '<"top"f>rt<"bottom"><"row dt-margin"<"col-md-6"i><"col-md-6"p><"col-md-12"B>><"clear">',
                    "buttons":  [ 'copy', 'csv', 'excel', 'pdf', 'print' ],
                    "stateSave": true,
                    "fixedHeader": false,
                    "oLanguage": {
                        "sSearch": "",
                        "sEmptyTable": "<?php _e('Oops! Er is niets om weer te geven.'); ?>",
                        "sZeroRecords": "<?php _e('Niets gevonden'); ?>",
                        "sInfo": "<?php _e('Weergeven van: '); ?> _START_ <?php _e('tot'); ?> _END_ <?php _e('van'); ?> _TOTAL_ <?php _e('records.'); ?>",
                        "sInfoEmpty": "",
                        "oPaginate": {
                            "sNext": "<?php _e('Volgende'); ?>",
                            "sPrevious": "<?php _e('Vorige'); ?>",
                            "sFirst": "<?php _e('Eerste pagina'); ?>",
                            "sLast": "<?php _e('Laatste pagina'); ?>"
                        }
                    },
                    "columnDefs": [ { "orderable": false, "targets": -1 } ] }
                );

--- html ---
<div class="table-responsive">
                                <table id="dataTablesFull" class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>Naam</th>
                                            <th>E-mail</th>
                                            <th>Antwoord</th>
                                            <th>Status</th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach ($contacts as $contact) { ?>

                                            <tr>
                                                <td>
                                                    <?php echo $name; ?>
                                                </td>
                                                <td>
                                                    <?php echo $email; ?>
                                                </td>
                                                <td>
                                                    <?php
                                                        if(empty($answer)) {
                                                            echo " -";
                                                        }
                                                        if(!empty($answer)) {
                                                            echo $answer;
                                                        }
                                                    ?>
                                                </td>
                                                <td>
                                                    <?php
                                                        if($contact['status'] == 0) {
                                                            echo "Verzonden";
                                                        }
                                                        if($contact['status'] == 1) {
                                                            echo "Beantwoord";
                                                        }
                                                    ?>
                                                </td>
                                                <td>
                                                    <div class='pull-right btn-group'>
                                                        <a href="#" onClick='#' class='btn btn-info btn-flat btn-sm'><i class='fa fa-eye'></i></a>
                                                        <a href="#" onClick='#' class='btn btn-danger btn-flat btn-sm'><i class='fa fa-trash-o'></i></a>
                                                    </div>
                                                </td>
                                            </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            </div>

【问题讨论】:

    标签: javascript html jquery datatables


    【解决方案1】:

    要显示按钮,您需要在“dom”选项上添加“B”(即 Buttons)

    要显示搜索栏,您需要在“dom”选项中添加“f”(即 filter)

    对于分页,您需要在“dom”选项中添加“p”。 (即p激动)

    $('#myTable').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'excel', 'pdf'
        ]
    } );
    

    参考https://datatables.net/reference/option/domhttps://datatables.net/extensions/buttons/

    您似乎将它们放在那里,但应用了额外的样式,可能是所引用的样式表未加载(通过浏览器开发工具检查)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      相关资源
      最近更新 更多