jquery - 数据表水平滚动不起作用

标签 jquery html css datatable

HTML代码:

<table  class="display table table-bordered table-striped" id="example" cellspacing="0" width="100%">
  <thead>
  <tr>
      <th>Create Date</th>
      <th>Project Name</th>
      <th>Property Type</th>
      <th>Project Address</th>
      <th>Area</th>
      <th>ZIP Code</th>
      <th>City</th>
      <th>State</th>
      <th>Owner Name</th>
      <th>Owner E-mail</th>
      <th>Owner Mobile</th>
      <th>Owner Type</th>
      <th>BHK</th>
      <th>Bathroom</th>
      <th>Balcony</th>
      <th>Builtup</th>
      <th>Carpet</th>
      <th>Unit</th>
      <th>Furniture Status</th>
      <th>Sell Type</th>
      <th>Sell Price</th>
      <th>Registration Charge</th>
      <th>Monthly Rent</th>
      <th>Maintanace</th>
      <th>Security Deposit</th>
      <th>Bachelors</th>
  </tr>
  </thead>
  <tbody>
    <tr class="gradeX">
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
        <td>1</td>
    </tr>
  </tbody>
  <tfoot>
  <tr>
      <th>Create Date</th>
      <th>Project Name</th>
      <th>Property Type</th>
      <th>Project Address</th>
      <th>Area</th>
      <th>ZIP Code</th>
      <th>City</th>
      <th>State</th>
      <th>Owner Name</th>
      <th>Owner E-mail</th>
      <th>Owner Mobile</th>
      <th>Owner Type</th>
      <th>BHK</th>
      <th>Bathroom</th>
      <th>Balcony</th>
      <th>Builtup</th>
      <th>Carpet</th>
      <th>Unit</th>
      <th>Furniture Status</th>
      <th>Sell Type</th>
      <th>Sell Price</th>
      <th>Registration Charge</th>
      <th>Monthly Rent</th>
      <th>Maintanace</th>
      <th>Security Deposit</th>
      <th>Bachelors</th>
  </tr>
  </tfoot>
</table>

jQuery 代码:

  $(document).ready(function() {
      $('#example').dataTable( {
          "aaSorting": [[ 4, "desc" ]],
          "scrollX": true
      } );
  } );

我从官方数据表网站复制了 jQuery 代码。但它不在我的网站上工作。我试过sscrollX。它工作但它改变了 th 和 td 的宽度。我该如何解决?请帮我。抱歉我的英语不好。

最佳答案

将此 css 添加到您的数据表容器:

    overflow-x: auto;

关于jquery - 数据表水平滚动不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43096702/

相关文章:

javascript - jQuery 与 slideToggle 一起禁用和启用滚动

javascript - 如何设置一个条件,让我的函数在所有值都为 true 时继续运行?

javascript - 仅水平滚动一个 div

html - 如何从 R 中指定类的网站解析地址?

html - 当页面不是全宽时,响应式 css 日历格式会中断

Javascript:非线性范围 slider

用于移动集成的 Jquery 菜单 - 从移动分辨率移动到桌面无法正常工作

html - 在 CSS 中定义替代图像路径

javascript - 我现在有一个下拉菜单如何使用 css 在一个链接内创建子菜单

javascript - 我自己的工具提示中的 href