如何在DataTables中初始化div?

时间:2019-05-02 11:02:08

标签: javascript jquery html css datatables

我已在我的应用程序中安装了一个DataTable,它返回一个错误,提示“ DataTables警告:非表节点初始化(DIV)。有关此错误的更多信息,请参见http://datatables.net/tn/2”。

现在,我了解DataTables结构旨在与 一起使用,但是我想在内部使用span和div,如下面的预览所示。

数据表如何在这种结构上工作?或者,如果有什么好的替代品可以完成相同的工作?

谢谢。

$('#dt').DataTable();

// COLLAPSE TABLE
$('tr[data-toggle="collapse"]').click(function(){
$('.insert-here').toggle();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin=" anonymous"></script>
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="//cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css">

 <div class="table-responsive">
  <!-- Table -->
  <table class="table" id="dt">
    <!-- Table Headings -->
    <thead class="table-header">
      <tr>
        <th scope="col"></th>
        <th scope="col">ID</th>
        <th scope="col">Name</th>
        <th scope="col">Type</th>
        <th scope="col">Status <span class="badge badge-danger profile-verification-noti">4</span></th>
        <th scope="col">Last Login</th>
        <th scope="col"></th>
      </tr>
    </thead>
    <tbody>

      <!-- Table Row 1 -->
      <tr class="table-chevron" data-toggle="collapse" data-target="#AccountDetails">
        <td><a href="javascript:void(1);" class="right-angle option-tab"><i class="fas fa-angle-right"></i></a></td>
        <td>[0708]</td>
        <td>Mark Jonas</td>
        <td>Guest</td>
        <td class="success">Active</td>
        <td>22/11/2018</td>
        <td><a href="#" class="fa-user-imp-text"><i class="fas fa-desktop"></i></a></td>
      </tr>

      <tr>
        <td class="insert-here coll-bg" colspan="8">
          <!-- START OF COMPLETE ACCOUNT SETTINGS -->
          <div class="collapse" id="AccountDetails">
            <div class="col-12 pl-0 mt-3">
              <!-- START OF ACCOUNT SETTINGS -->
              <div class="col-4 pl-0 account-details-box float-left">
                <h2 class="accounts-heading">Account Settings</h2>
                <!-- Account Status -->
                <div class="row">
                  <div class="col-md-6 mb-3 float-left">
                    <p>Account Status</p>
                  </div>
                  <div class="col-md-6 mb-3 pl-0 float-left ac-set">
                    <select class="form-control custom-select col-md-11">
                      <option>Active</option>
                      <option>Disabled</option>
                      <option>Deleted</option>
                      <option>Pending</option>
                    </select>
                  </div>
                </div>
                <!-- Account Manager -->
                <div class="row">
                  <div class="col-md-6 mb-3 float-left">
                    <p>Account Manager</p>
                  </div>
                  <div class="col-md-6 mb-5 pl-0 float-left ac-set">
                    <select class="form-control custom-select col-md-11">
                      <option selected="selected">--</option>
                      <option>Bilal Khan</option>
                      <option>Rishabh Saxena</option>
                      <option>Abhishekh Joshi</option>
                    </select>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </td>
      </tr>
    </tbody>
  </table>
 </div>

1 个答案:

答案 0 :(得分:0)

在您的代码中搜索,也许您已在代码中两次初始化了dataTable。 您持有这样的代码:

$('#example').dataTable( {paging: false} );

只有一次。