繁体   English   中英

数据表警告(表 id = 'example')

[英]Datatables warning(table id = 'example')

早上好,

我有一个关于数据表的问题。

在教程中,我找到了一个可以编辑“内联”的表。 我想要一张德文的桌子。

表的代码:

 <script type="text/javascript" language="javascript" > $(document).ready(function(){ var dataTable = $('#sample_data').DataTable({ "processing": true, "serverSide": true, "order": [], "ajax": { url:"fetch.php", type:"POST" } }); $('#sample_data').on('draw.dt', function(){ $('#sample_data').Tabledit({ url:'action.php', dataType:'json', columns:{ identifier: [0, 'id'], editable:[[1, 'nachname'], [2, 'vorname'], [3, 'datum', '{"1":"Male","2":"Female"}']] }, restoreButton:false, onSuccess:function(data, textStatus, jqXHR) { if(data.action == 'delete') { $('#' + data.id).remove(); $('#sample_data').DataTable().ajax.reload(); } } }); }); }); </script>
 HTML-Code: <html> <head> <title>How to use Tabledit plugin with jQuery Datatable in PHP Ajax</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script> <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script src="https://markcell.github.io/jquery-tabledit/assets/js/tabledit.min.js"></script> </head> <body> <div class="container"> <h3 align="center">How to use Tabledit plugin with jQuery Datatable in PHP Ajax</h3> <br /> <div class="panel panel-default"> <div class="panel-heading">Sample Data</div> <div class="panel-body"> <div class="table-responsive"> <table id="sample_data" class="table table-bordered table-striped"> <thead> <tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Gender</th> </tr> </thead> <tbody></tbody> </table> </div> </div> </div> </div> <br /> <br /> </body> </html>

语言设置德语的代码:

$(document).ready( function () {
    $('#sample_data').DataTable({
    lengthMenu: [[25, 50, 100, 150, 200, 300, 400, 500], [25, 50, 100, 150, 200, 300, 400, 500]],
    dom: 'Bfrtip',
        buttons: [
        {
            extend: 'copy',
            text: '<i class="fa fa-clone" aria-hidden="true"></i> Kopieren',
        },
        {
            extend: 'print',
            text: '<i class="fa fa-print" aria-hidden="true"></i> Drucken'
        },
        {
            extend: 'excel',
            text: '<i class="fa fa-table" aria-hidden="true"></i> Excel'
        },
        {
            extend: 'pdf',
            text: '<i class="far fa-file-pdf"></i> PDF'
        }
    ],
    language: {
            "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json",
            searchPlaceholder: "Suchbegriff eingeben...",
        }    
    } );    
} );

谁能帮我? 不幸的是,我没有进一步了解。 我得到错误:

DataTables 警告:table id=sample_data - 无法重新初始化 DataTable。 有关此错误的更多信息,请参阅http://datatables.net/tn/3

如果您面临的错误Cannot reinitialise DataTable ,那么您应该在初始化 DataTable 之前销毁,例如

var dataTable = undefined;
$(document).ready( function () {
    if(dataTable) dataTable.destroy();

    dataTable = $('#sample_data').DataTable({
    lengthMenu: [[25, 50, 100, 150, 200, 300, 400, 500], [25, 50, 100, 150, 200, 300, 400, 500]],
    dom: 'Bfrtip',
        buttons: [
        {
            extend: 'copy',
            text: '<i class="fa fa-clone" aria-hidden="true"></i> Kopieren',
        },
        {
            extend: 'print',
            text: '<i class="fa fa-print" aria-hidden="true"></i> Drucken'
        },
        {
            extend: 'excel',
            text: '<i class="fa fa-table" aria-hidden="true"></i> Excel'
        },
        {
            extend: 'pdf',
            text: '<i class="far fa-file-pdf"></i> PDF'
        }
    ],
    language: {
            "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json",
            searchPlaceholder: "Suchbegriff eingeben...",
        }    
    } );    
} );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM